TreeNode

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
Exam Prep. Guides
70-505 Study Guide
70-526 Study Guide

1. Forms Controls

2. Integrating Data
3. Printing/Reporting
4. Enhancing Usability
5. Asynchronous Prog.
6. Forms Controls
7. Configure/Deploy

edit
Exam 70-526 Preparation Guide: Configure the layout and functionality of a Windows Form to display a list of items


Contents


Each node in a TreeView is an instance of the TreeNode class. A TreeNode contains information about its location within a TreeView and any child nodes that it may contain.

Image:526-98.jpg


Inheritance hierarchy

System.Object
  System.MarshalByRefObject
    System.Windows.Forms.TreeNode


Useful properties

  • FirstNode - Gets the first child tree node in the tree node collection.
  • ImageIndex - Gets or sets the image-list index value of the default image that is displayed by the tree nodes. By default this value is equal to TreeView.ImageIndex. To specify another image index, you must set this property explicitly.
  • LastNode - Gets the last child tree node.
  • NextNode - Gets the next sibling tree node.
  • NextVisibleNode - Gets the next visible tree node.
  • Nodes - Gets the collection of TreeNode objects assigned to the current tree node.
  • Parent - Gets the parent tree node of the current tree node. If the current node is a root node in the TreeView, accessing this property will throw a NullReferenceException.
  • PrevNode - Gets the previous sibling tree node.
  • PrevVisibleNode - Gets the previous visible tree node.
  • SelectedImageIndex - Defines the image list index value of the image that is displayed when the tree node is in the selected state. By default this value is equal to TreeView.SelectedImageIndex. To specify another image index, you must set this property explicitly.
  • Text - Defines the text displayed in the label of the tree node.
  • TreeView - Gets the parent tree view that the tree node is assigned to.


Expanding or Collapsing nodes manually

At some point you may wish to expand or collapse a node within a TreeView without intervention form the user. This is done through the use of two methods within the TreeNode class.

To expand a node, call the method Expand as follows:

Node1.Expand();

To collapse a node, call the method Collapse as follows:

Node1.Collapse();


MSDN references


Previous_Page_.gif Next_Page_.gif
© 2007-2008 Mike Kitchen

Personal tools