0% found this document useful (0 votes)
14 views

Using Using Using Namespace Public Partial Class Public: Form1 Form

The document creates a tree structure with nodes in a TreeView control. It adds a root node called "RootNode", then adds 4 child nodes under the root. It also adds 2 next child nodes under one of the child nodes. The tree is then expanded to display all nodes.

Uploaded by

Robin Nelson
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Using Using Using Namespace Public Partial Class Public: Form1 Form

The document creates a tree structure with nodes in a TreeView control. It adds a root node called "RootNode", then adds 4 child nodes under the root. It also adds 2 next child nodes under one of the child nodes. The tree is then expanded to display all nodes.

Uploaded by

Robin Nelson
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System; using System.Drawing; using System.Windows.

Forms; namespace TreeView { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { TreeNode ParentNode = new TreeNode(); ParentNode.Text = "RootNode"; ParentNode.ForeColor = Color.Black; ParentNode.BackColor = Color.White; ParentNode.ImageIndex = 0; ParentNode.SelectedImageIndex = 0; treeView1.Nodes.Add(ParentNode); //Root node in TreeView TreeNode ChildNode1 = new TreeNode(); ChildNode1.Text = "Child 1"; ChildNode1.ForeColor = Color.Black; ChildNode1.BackColor = Color.White; ChildNode1.ImageIndex = 0; ChildNode1.SelectedImageIndex = 0; ParentNode.Nodes.Add(ChildNode1); TreeNode ChildNode2 = new TreeNode(); ChildNode2.Text = "Child 2"; ChildNode2.ForeColor = Color.Black; ChildNode2.BackColor = Color.White; ChildNode2.ImageIndex = 0; ChildNode2.SelectedImageIndex = 0; ParentNode.Nodes.Add(ChildNode2); TreeNode ChildNode3 = new TreeNode(); ChildNode3.Text = "Child 3"; ChildNode3.ForeColor = Color.Black; ChildNode3.BackColor = Color.White; ChildNode3.ImageIndex = 0; ChildNode3.SelectedImageIndex = 0; ParentNode.Nodes.Add(ChildNode3); TreeNode ChildNode4 = new TreeNode(); ChildNode4.Text = "Child 4"; ChildNode4.ForeColor = Color.Black; ChildNode4.BackColor = Color.White; ChildNode4.ImageIndex = 0; ChildNode4.SelectedImageIndex = 0; ParentNode.Nodes.Add(ChildNode4); TreeNode NextChildNode1 = new TreeNode(); NextChildNode1.Text = "Next Child 1"; NextChildNode1.ForeColor = Color.Black; NextChildNode1.BackColor = Color.White;

//Child node (parent is ParentNode)

//Child node (parent is ParentNode)

//Child node (parent is ParentNode)

//Child node (parent is ParentNode)

NextChildNode1.ImageIndex = 1; NextChildNode1.SelectedImageIndex = 1; ChildNode3.Nodes.Add(NextChildNode1); TreeNode NextChildNode2 = new TreeNode(); NextChildNode2.Text = "Next Child 2"; NextChildNode2.ForeColor = Color.Black; NextChildNode2.BackColor = Color.White; NextChildNode2.ImageIndex = 1; NextChildNode2.SelectedImageIndex = 1; ChildNode3.Nodes.Add(NextChildNode2); treeView1.ExpandAll(); } } }

//Child node (parent is ChildNode3)

//Child node (parent is ChildNode3)

You might also like