Articles in this section
Category / Section

How to dynamically add the node to TreeView control?

1 min read

Description:

You can add a node to TreeView programmatically, by defining and adding an object of TreeViewNode class to the TreeView control.

Solution:

To add the Menu Item in Menu control, you need to do the following:

  1. Define the properties of TreeView node object, like Text, expanded with help of TreeViewNode class.
  2. Add the defined item object to the TreeView control by using the Add() method.

Refer the given code example.

C#               

TreeViewNode rootNode = new TreeViewNode();
rootNode.Text = "MailBox";
rootNode.Expanded = true;
tree.Items.Add(rootNode); 
/* tree - TreeView control is already defined in a designer page. 
Adding the new TreeViewNode item using add method.*/

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied