)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to retrieve the TreeNodeAdv from TreeNodeAdvCollection without performing iteration process in the WinForms TreeViewAdv?

Platform: WinForms |
Control: TreeViewAdv |
Published Date: May 27, 2015 |
Last Revised Date: February 5, 2020

Retrieve the TreeNodeAdv from TreeNodeAdvCollection

In the TreeViewAdv, it is possible to retrieve a particular TreeNodeAdv based on the custom property. Refer to the following steps.

1. Load TreeNodeAdv to custom collection while adding the TreeNodeAdv to TreeViewAdv nodes collection.

2. Then, you can retrieve the TreeNodeAdv based on index value from the custom collection.

C#

//Stores the TreeNodeAdv to list.
private List<TreeNodeAdv> nodecollection = new List<TreeNodeAdv>();
//Initializes the TreeNodeAdv
private TreeNodeAdv node = new TreeNodeAdv();
for (int nodeId = 0; nodeId <= 10000; nodeId++)
{
    //Custom node for ID propety
    CustomTreeNodeAdv customNode = new CustomTreeNodeAdv();
    customNode.ID = nodeId;
    customNode.Text = "Node" + nodeId.ToString();
    this.treeViewAdv1.Nodes.Add(customNode);
    nodecollection.Add(customNode);
}
//Gets the TextBox value
int textvalue = Int32.Parse(this.integerTextBox1.Text);
//Gets the TreeNodeAdv from list
node = nodecollection[textvalue];
//Shows the selected node text
MessageBox.Show(node.Text);

VB

'Stores TreeNodeAdv to list.
Private nodecollection As New List(Of TreeNodeAdv)()
'Initializes the TreeNodeAdv
Private node As New TreeNodeAdv()
For nodeId As Integer = 0 To 10000
     'Custom node for ID propety
     Dim customNode As New CustomTreeNodeAdv()
     customNode.ID = nodeId
     customNode.Text = "Node" & nodeId.ToString()
     Me.treeViewAdv1.Nodes.Add(customNode)
     nodecollection.Add(customNode)
Next nodeId
'Gets the text box value
Dim textvalue As Integer = Int32.Parse(Me.integerTextBox1.Text)
'Gets the node from list
node = nodecollection(textvalue)
'Shows the selected node text
MessageBox.Show(node.Text)

Samples:

C#: http://www.syncfusion.com/downloads/support/directtrac/138428/TreeNodeAdv-1281820906.zip

VB: http://www.syncfusion.com/downloads/support/directtrac/138428/TreeNodeAdv_VB-985453358.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon