Class Hierarchy of TreeView Control
TreeView
TreeNodeCollection
TreeNode
TreeView is contains collection of TreeNodes. Each TreeNode is a member of TreeNodeCollection.
TreeNode
is a type of recursive Data Structure as itself contains Collection of
TreeNodes. All TreeNodes are number from 0 to Nodes.Count-1 sequentially
in the order of appearance irrespective of the hierarchial structure
eg.
ROOT
T1
T11
T2
For the above structure the nodes are numbered as
ROOT - 1
T1 - 2
T11 - 3
T2 - 4
1.Creating TreeView
TreeView is created by instancing the TreeView class.
eg.
TreeView tvSample = new TreeView();
2.Add Nodes to TreeView
The Nodes property of the TreeView is an instance of TreeNodeCollection class
which is used to Add/Remove Nodes.
eg.
tvSample.Nodes.Add("Sample")
or
tvSample.Nodes.Add(new TreeNode("Sample"))
3.Removing Nodes from TreeView
The Nodes Property of the TreeView is an instance of TreeNodeCollection class
which is used to Add/Remove Nodes.
eg.
tvSample.Nodes.RemoveAt(1) //To Remove the First appearing node in the Tree.
or
tvSample.Nodes.Remove(tvSample.SelectedNode) //Removes the currently selected node.
4.Determine the SelectedNode
SelectedNode property is used to determine the currently selected node in the
Tree.
eg.
string nodeText=tvSample.SelectedNode.Text;
will retrieve the Text of the selected node.
for more information refer to the below link,
http://www.c-sharpcorner.com/UploadFile/prasadh/TreeViewControlInWinFormsPSD11182005235448PM/TreeViewControlInWinFormsPSD.aspx
hope it helps you.