Articles in this section
Category / Section

How to improve WinForms TreeViewAdv's performance when selecting more than a thousand nodes?

1 min read

Performance of TreeViewAdv

The performance of WinForms  TreeViewAdv when selecting more than thousand nodes can be improved by handling the following TreeViewAdv events:

1. MouseUp event

2. KeyUp event

3. KeyDown event

C#

void treeViewAdv1_MouseUp(object sender, MouseEventArgs e)
{
    if(Control.ModifierKeys == Keys.Shift)
    {
       TreeNodeAdv node = this.treeViewAdv1.PointToNode(e.Location);
       int index = this.treeViewAdv1.NodeToRowIndex(node);
       int endindex = this.treeViewAdv1.NodeToRowIndex(this.treeViewAdv1.SelectedNode);
       int incre=index>endindex?-1:1;                
       this.treeViewAdv1.SelectedNodes.Clear();                            
       for (int i = index; ; i += incre)
       {
           this.treeViewAdv1.SelectedNodes.Add(this.treeViewAdv1.RowIndexToNode(i));
           if(endindex == i)
           {
              break;
           }
       }                
    }
}

VB

Private Sub treeViewAdv1_MouseUp(sender As Object, e As MouseEventArgs)
   If Control.ModifierKeys = Keys.Shift Then
      Dim node As TreeNodeAdv = Me.treeViewAdv1.PointToNode(e.Location)
      Dim index As Integer = Me.treeViewAdv1.NodeToRowIndex(node)
      Dim endindex As Integer = Me.treeViewAdv1.NodeToRowIndex(Me.treeViewAdv1.SelectedNode)
      Dim incre As Integer = If(index > endindex, -1, 1)
      Me.treeViewAdv1.SelectedNodes.Clear()
      Dim i As Integer = index
      While True
           Me.treeViewAdv1.SelectedNodes.Add(Me.treeViewAdv1.RowIndexToNode(i))
           If endindex = i Then
              Exit While
           End If
           i += incre
      End While
   End If
End Sub

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/TreeViewAdvSample946095543.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied