Share via


How to: Add a Node to the Selected Node of a TreeView Control

This example adds one node to the selected node of an existing TreeView control.

Example

try
{
    TreeNode node = treeView1.SelectedNode;
    node.Nodes.Add("New node below selected node");
}
catch (Exception)
{
    // Handle the exception.
} 

Compiling the Code

This example requires:

Robust Programming

The following conditions may cause an exception:

  • The TreeView control has no nodes or none of the nodes is selected.

See Also

Concepts

Designing a User Interface in Visual C#

Other Resources

TreeView Controls

Visual C# Guided Tour