TreeNode.Index Property

Gets the position of the tree node in the tree node collection.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public int Index { get; }

Property Value

Type: System.Int32
A zero-based index value that represents the position of the tree node in the Nodes collection.

The following code example displays the Text and Index property values of the TreeNode represented by the Parent property of the TreeView.SelectedNode. This example requires that you have a Form with a TreeView control on it. The TreeView should have at least two root nodes, each having at least one child node.

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{  
   /* Display the Text and Index of the 
    * selected tree node's Parent. */ 
   if(e.Node.Parent!= null && 
     e.Node.Parent.GetType() == typeof(TreeNode) )
   {
      statusBar1.Text = "Parent: " + e.Node.Parent.Text + "\n"
         + "Index Position: " + e.Node.Parent.Index.ToString();
   }
   else
   {
      statusBar1.Text = "No parent node.";
   }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft