'Nothing happens when I RIGHT click the Tree Node on the TreeView (Windows Form)

I am trying to create a new node when I right click on the treenode.

private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        treeView1.Nodes[0].Nodes.Add("Folder");
    }
}


Solution 1:[1]

It's working for me. Check if the event is associated. Also, if you want add a child node, use SelectedNode.

private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
    if (e.Button == MouseButtons.Right && treeView1.SelectedNode != null)
    {
        treeView1.SelectedNode.Nodes.Add("Folder");
            
        // To make visible the inserted node
        treeView1.SelectedNode.Expand();
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Victor