carlAlex
8/10/2016 - 8:31 AM

C# TreeView

C# TreeView

Add nodes:

	    //
	    // This is the first node in the view.
	    //
	    TreeNode treeNode = new TreeNode("Windows");
	    treeView1.Nodes.Add(treeNode);
	    //
	    // Another node following the first node.
	    //
	    treeNode = new TreeNode("Linux");
	    treeView1.Nodes.Add(treeNode);
	    //
	    // Create two child nodes and put them in an array.
	    // ... Add the third node, and specify these as its children.
	    //
	    TreeNode node2 = new TreeNode("C#");
	    TreeNode node3 = new TreeNode("VB.NET");
	    TreeNode[] array = new TreeNode[] { node2, node3 };
	    //
	    // Final node.
	    //
	    treeNode = new TreeNode("Dot Net Perls", array);
	    treeView1.Nodes.Add(treeNode);

Double-click on nodes:

	    //
	    // Get the selected node.
	    //
	    TreeNode node = treeView1.SelectedNode;
	    //
	    // Render message box.
	    //
	    MessageBox.Show(string.Format("You selected: {0}", node.Text));