Articles in this section
Category / Section

How to add nodes to the WinForms TreeViewAdv using the Keyboard?

1 min read

Add nodes to TreeViewAdv

The nodes can be added to the TreeViewAdv when any key is pressed whereby the text of the node reflects the key that has been used for adding the node by using the following code in the TreeViewAdv KeyDown Event handler.

C#

private void treeViewAdv1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
   TreeNodeAdv node=new TreeNodeAdv("Node"+" "+e.KeyData.ToString());
   this.treeViewAdv1.SelectedNode.Nodes.Add(node);
   Console.WriteLine("The "+node.Text+" "+"is added");
}

VB

Private Sub treeViewAdv1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
   Dim node As TreeNodeAdv = New TreeNodeAdv("Node" & " " & e.KeyData.ToString())
   Me.treeViewAdv1.SelectedNode.Nodes.Add(node)
   Console.WriteLine("The " & node.Text & " " & "is added")
End Sub

 

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