Add Nodes to TreeView : TreeView « GUI Windows Form « C# / C Sharp





Add Nodes to TreeView

 

using System;
using System.Drawing;
using System.Windows.Forms;
   
class SimpleTreeView: Form
{
     public static void Main()
     {
          Application.Run(new SimpleTreeView());
     }
     public SimpleTreeView()
     {
          Text = "Simple Tree View";
   
          TreeView tree = new TreeView();
          tree.Parent = this;
          tree.Dock = DockStyle.Fill;
   
          tree.Nodes.Add("Animal");
          tree.Nodes[0].Nodes.Add("A");
          tree.Nodes[0].Nodes[0].Nodes.Add("A1");
          tree.Nodes[0].Nodes[0].Nodes.Add("A2");
          tree.Nodes[0].Nodes[0].Nodes.Add("A3");
          tree.Nodes[0].Nodes.Add("B");
          tree.Nodes[0].Nodes[1].Nodes.Add("B1");
          tree.Nodes[0].Nodes[1].Nodes.Add("B2");
          tree.Nodes[0].Nodes.Add("C");
          tree.Nodes[0].Nodes[2].Nodes.Add("C1");
          tree.Nodes[0].Nodes[2].Nodes.Add("C2");
          tree.Nodes[0].Nodes[2].Nodes.Add("C3");
          tree.Nodes.Add("D");
          tree.Nodes[1].Nodes.Add("D1");
          tree.Nodes[1].Nodes.Add("D2");
          tree.Nodes[1].Nodes.Add("D3");
          tree.Nodes.Add("E");
          tree.Nodes[2].Nodes.Add("E1");
          tree.Nodes[2].Nodes.Add("E2");
          tree.Nodes[2].Nodes.Add("E3");
     }
}

 










Related examples in the same category

1.Recursively load Directory info into TreeViewRecursively load Directory info into TreeView
2.Drag and drop Tree NodeDrag and drop Tree Node
3.Get Selected Node Full PathGet Selected Node Full Path
4.Custom TreeView
5.TreeView ExampleTreeView Example
6.TreeView Drag And DropTreeView Drag And Drop
7.TreeView Data BindingTreeView Data Binding
8.Read an XML Document and display the file as a TreeRead an XML Document and display the file as a Tree
9.TreeView DemoTreeView Demo
10.Directory Tree HostDirectory Tree Host
11.Subclass TreeView
12.TreeView ImageIndex