Checkbox CheckedState Changed Event

1 Answer 87 Views
RichTextBox
maik
Top achievements
Rank 1
maik asked on 20 Sep 2023, 03:15 PM

Hello Everyone,

I am currently Testing if we can switch from Word to Telerik RadRichTextbox. For that i want to be able to get notifications/events when a User Clicks on a Checkbox. I know there is the DocumentContentChanged event but that fires always and i dont think that ist viable for a document with many Checkboxes.

Is there some Event that would tell me which Control was changed?

Dimitar
Telerik team
commented on 25 Sep 2023, 06:08 AM

Hi Maik, 

The selected product for this thread is WinUI but this suite does not have a RadRichTextBox. Can you specify the exact product you want to use in this case? Perhaps WPF or Winforms? 

I am looking forward to your reply.

Charlotte
Top achievements
Rank 1
commented on 20 Oct 2023, 03:34 AM

In Telerik RadRichTextBox, there is an event called FieldClicked that you can use to get notifications when a user clicks on a checkbox or any other field within the document. This event specifically provides information about the clicked field.
maik
Top achievements
Rank 1
commented on 23 Oct 2023, 12:31 PM

Thank you for your response. I apologize for the confusion;

I mistakenly posted in the WinUI forum when I should have posted in the WPF forum.

I am unable to locate the FieldClicked event in the RadRichTextBox or in any of your documentation. Could you please share a simple demo app or provide more information about the FieldClicked event?

Thank you very much!

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 24 Oct 2023, 07:13 AM

Hello Maik,

You can use the following approach to get the clicked checkbox: 

private void RadRichTextBox_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    var parentPanel = (RadRichTextBox)sender;

    Point pt = e.GetPosition(parentPanel);

    VisualTreeHelper.HitTest(parentPanel, null,
        new HitTestResultCallback(MyHitTestResult),
        new PointHitTestParameters(pt));
}

public HitTestResultBehavior MyHitTestResult(HitTestResult result)
{
    if (result.VisualHit != null)
    {
        var contentControl = result.VisualHit.GetParents().OfType<CheckBoxControl>().FirstOrDefault();

        if (contentControl != null)
        {
            MessageBox.Show("Check Box Clicked");
        }
    }

    return HitTestResultBehavior.Continue;
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

maik
Top achievements
Rank 1
commented on 10 Jan 2024, 07:33 PM

Thanks for the answer!

I just tested it again after a long time and forgot to mention that I have several ContentControls in my document and I want to be able to identify the exact clicked ContentControl. Is there a way to do this?

Dimitar
Telerik team
commented on 11 Jan 2024, 12:27 PM

Hi Maik,

You can use the Tag property for this (see attached). 

Let me know if you have additional questions.

maik
Top achievements
Rank 1
commented on 11 Jan 2024, 03:01 PM

Hey Dimitar,

thanks for the reply,

im directly referencing the code above where i have the Method MyHitTestResult.

when I Click on the Checkbox and Debug to the Point:

var contentControl = result.VisualHit.GetParents().OfType<CheckBoxControl>().FirstOrDefault();

I will find the FirstorDefault control from Type Telerik.Windows.Controls.RichTextBoxUI.CheckBoxControl

 but the Property is always Empty.

I already added a Tag and a Title to every Checkbox in my Document like you showed in the Attachment

thanks in advance

 

 

Dimitar
Telerik team
commented on 12 Jan 2024, 07:37 AM

Hi Maik, 

The Tag property of the control is different. You can get the Tag from the SdtProperties. Here is an example:

var contentControl = result.VisualHit.GetParents().OfType<CheckBoxControl>().FirstOrDefault();

if (contentControl != null)
{
    var range = radRichTextBox.Document.CaretPosition.GetCurrentInline() as SdtRangeEnd;
    if (range != null)
    {
        var tag = ((SdtRangeStart)range.Start).SdtProperties.Tag;
    }
}

Let me know if I can be of further assistance.

Tags
RichTextBox
Asked by
maik
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or