Changing checkbox state when user clicks on the node label

3 posts, 0 answers
  1. Lou
    Lou avatar
    64 posts
    Member since:
    Aug 2014

    Posted 19 Jan 2017 Link to this post

    How do I change a node's checkbox state when the user clicks on the node's label text as opposed to clicking on the checkbox itself? 

    This needs to work when the treeview is in Tri-state mode (needs to handle intedeterminate state as well as on/off). 

    Thanks

     

  2. Dimitar
    Admin
    Dimitar avatar
    2570 posts

    Posted 20 Jan 2017 Link to this post

    Hi Lou,

    Thank you for writing.

    The following example shows how you can achieve this:
    public RadForm1()
    {
        InitializeComponent();
        radTreeView1.Click += RadTreeView1_Click;
        radTreeView1.NodeFormatting += RadTreeView1_NodeFormatting;
    }
     
    private void RadTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
    {
        e.NodeElement.ContentElement.ShouldHandleMouseInput = true;
     
    }
     
    private void RadTreeView1_Click(object sender, EventArgs e)
    {
        var element = radTreeView1.ElementTree.GetElementAtPoint(((MouseEventArgs)e).Location);
        if (element is TreeNodeContentElement)
        {
            var node = element.Parent as TreeNodeElement;
            node.Data.Checked = !node.Data.Checked;
        }
    }

    I hope this information is useful. Let me know if you need further assistance.

    Regards,
    Dimitar
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Lou
    Lou avatar
    64 posts
    Member since:
    Aug 2014

    Posted 20 Jan 2017 in reply to Dimitar Link to this post

    Thanks Dimitar, that worked.

    -Lou

Back to Top