Cascading checkbox nodes - how do I know when cascading is all done?

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

    Posted 20 Jan 2017 Link to this post

    Hi,

    I am using a TreeView with checkboxes enabled and TriState enabled. If I click on a parent node checkbox it affects the checkbox state of its children, and vice versa. I would like to be able to save the tree state whenever the tree checkboxes are changed by a user, but only when ALL of the cascading is finished.

    How can I do that?

    Note: I tried to use the TreeView1.NodeCheckedChanged event - but this event fires for EVERY checkbox change. I only want to run my code once, at the very end.

    Thanks,

    -Lou

  2. Hristo
    Admin
    Hristo avatar
    1507 posts

    Posted 23 Jan 2017 Link to this post

    Hi Lou,

    Thank you for writing.

    The check state for each of the nodes is evaluated raising the NodeCheckedChanging and NodeCheckedChanged events. However, there is no notification when this update finishes.

    Achieving your task is possible and for the purpose, you can handle the MouseUp event of the tree. By the time the event fires all of the nodes will have been updated. In the event handler you can perform a check for the clicked element and then iterate the tree: 
    public Form1()
    {
        InitializeComponent();
     
        this.radTreeView1.MouseUp += radTreeView1_MouseUp;
    }
     
    private void radTreeView1_MouseUp(object sender, MouseEventArgs e)
    {
        RadTreeView tree = (RadTreeView)sender;
        TreeNodeCheckBoxElement checkBox = tree.ElementTree.GetElementAtPoint(e.Location) as TreeNodeCheckBoxElement;
        if (checkBox != null)
        {
            //Save state.
        }
    }

    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo
    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.
Back to Top