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:
- Define the properties of TreeView node object, like Text, expanded with help of TreeViewNode class.
- 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.*/