RadTreeView Issue -- Can Select another node before SelectedNodeChange event finished

1 Answer 11 Views
Treeview
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Roger asked on 17 Nov 2025, 08:14 PM | edited on 17 Nov 2025, 08:14 PM

I have a situation where I have code that executes when the Selected Node  is changed.

SelectedNodeChanged

 

The code in the SelectedNodeChange adds controls to some FlowLayoutPanel.

When a user clicks on a node, you can see the controls being added to the control

but the RadTreeView allows the user to select another node eventhough the SelectedNodeChange event has not finished, which

is now causing issues with the FlowLayoutPanelshowing duplicate controls.

 

If user waits until all controls are in the FlowLayoutPanel, and then selects another node, everything works as expected.

 

None of the code that adds the controls to the FlowLayoutPanel are Asynchronous.

 

I DO NOT have Multiselect = true.

 

** I have noticed that the RadTreeView acts as though it is Asynchronous when filling it.  I have code that fills the nodes and you can select the nodes and see the nodes being added behind the scenes. 

Maybe control is Asynchronous when changing selected nodes?

 

 

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 18 Nov 2025, 10:00 AM

Hello, Roger,

RadTreeView operates synchronously when changing selected nodes. The SelectedNodeChanged event and all related selection operations execute immediately on the UI thread without any asynchronous behavior. However, rapid user interaction can queue multiple events if your processing code is slow or if the UI thread is busy updating controls in the FlowLayoutPanel.

The behavior you observe—users being able to select another node before the previous SelectedNodeChanged logic finishes—is due to the UI thread remaining responsive to input while your event handler is running. I can suggest you some options that can overcome this problem you are facing. However, the exact decision how to accomplish this is up to you. 

Option 1:

Implement a processing boolean flag to prevent overlapping event executions. You can update this flag when the operation finishes.


  private bool isProcessingNodeChange = false;
      
        private void radTreeView1_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
        {
            // Prevent overlapping event processing
            if (isProcessingNodeChange)
                return;

            try
            {
                isProcessingNodeChange = true;
                
                // Clear existing controls first
                flowLayoutPanel1.Controls.Clear();
                
                // Add your controls based on the selected node
                AddControlsToFlowLayout(e.Node);
            }
            finally
            {
                isProcessingNodeChange = false;
            }
        }
}

Option 2:

You can temporarily disable the RadTreeView while you process the SelectedNodeChanged event. This ensures users cannot select another node until your logic completes:

private void radTreeView1_SelectedNodeChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
{
    radTreeView1.Enabled = false; // Prevent further selection

    // Add controls to FlowLayoutPanel
    // ... your logic here ...

    radTreeView1.Enabled = true; // Re-enable selection
}

I am not certain how many controls you are adding in the FlowLayoutPanel and whether this operation is supposed to proceed long. If you are not satisfied with disabling RadTreeView, you can consider showing a waiting bar indicator that a long running operation is ongoing, or use a timer to track time. It is up to your preferences: https://docs.telerik.com/devtools/winforms/knowledge-base/using-radwaitingbar-to-indicate-the-status-of-long-running-operations

 

RadTreeView also offers SelectedNodeChanging event that occurs before a tree node selection changes and allows to be canceled upon some condition. You can use it to cancel node selection if the other process has not finished yet. 

I hope this information is useful. Let me know if you have any other questions.

Regards,
Nadya | Tech Support Engineer
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.

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 18 Nov 2025, 01:42 PM | edited

Nayda,

 

Thanks so much for the detailed response and code suggestions.  I was able to utilize code from the examples to solve my issue.

 

I set the boolean in the SelectedNodeChange event and checked that boolean in the SelectedNodeChanging event.

 private void tvLibraries_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
 {
     Cursor = Cursors.WaitCursor;
     isChanging = true;
     flowLayoutPanel1.Controls.Clear();
     resetMetaDataControls();
     treeNodePicked(e.Node);
     isChanging = false;
     Cursor = Cursors.Default;
 } 

 

 private void tvLibraries_SelectedNodeChanging(object sender, RadTreeViewCancelEventArgs e)
 {
     if (isChanging)
         e.Cancel = true;
 }

 

I am always impressed with the support Telerik has for their tools.

 

Roger

Nadya | Tech Support Engineer
Telerik team
commented on 19 Nov 2025, 09:26 AM

Hello, Roger,

Thank you for your feedback! I am really glad to hear that the provided code examples were helpful and that you were able to utilize them successfully to meet your requirements.

If you have any other questions, do not hesitate to contact me again. 

Tags
Treeview
Asked by
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or