RadTreeview SelectedNodeChange how to know if Unselect or Select is happening.

1 Answer 143 Views
Treeview
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Roger asked on 17 Feb 2022, 04:23 PM

I know that when you select a node this event is called.

If you select another node, it is called TWICE.

 

Is there a way to know which it is calling it for (Unselecting or Selecting).

This way I can skip code on the unselecting one and only do code on the newly selected node.

Thanks,

1 Answer, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 18 Feb 2022, 01:02 PM

Hello Roger,

By design, when multiple selections are allowed and you click a new node, the selection is supposed to be cleared. That is why the SelectedNodeChanged event is fired for the previously selected node first and then it is fired for the new node. In the RadTreeViewEventArgs you can distinguish the two event firings by the Action which is set to Unknown when the selection is cleared.

private void radTreeView1_SelectedNodeChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
{
    if (e.Action != Telerik.WinControls.UI.RadTreeViewAction.ByMouse)
    {
        Console.WriteLine(e.Node.Text);
    }
}

Another approach will be to check the Selected property of the node. If it is true, execute your logic.

private void RadTreeView1_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
{
    if (e.Node.Selected == true)
    {
        Console.WriteLine(e.Node.Text);
    }
}

I hope this information is helpful.

Regards,
Dinko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 18 Feb 2022, 01:41 PM

Thanks for this response it worked as you stated.

 

Is there a place in the documentation where this is shown? 

 

Thanks,

 

 

 

Dinko | Tech Support Engineer
Telerik team
commented on 22 Feb 2022, 02:40 PM

Thank you for the provided feedback. I have double-checked and this is not mentioned in the documentation. Therefore I have logged an internal item in our backlog to update the RadTreeView documentation. We appreciate any feedback from our customers. I have updated your Telerik Points for bringing this to our attention.
Tags
Treeview
Asked by
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or