How to add a child node to a selected parent node programmatically? C++ Winforms

José Carlos 886 Reputation points


I'm studying the treeView component and I'm having trouble adding a child node to a selected parent node via programming. The parent node is selected by the checkbox next to the name.

With the line below I add it, but inside the parentheses where there is zero I need to put the selected node and I am not succeeding.

The name of the child node is typed into a textBox2.



Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,684 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,559 questions
{count} votes

Accepted answer
  1. David Lowndes 4,711 Reputation points

    You should be able to use SelectedNode directly - no need to index into the collection. Something like this:

1 additional answer

Sort by: Most helpful
  1. José Carlos 886 Reputation points

    Hi Davi,

    I used this method inside the parentheses instead of zero, by logic that would be it, but it didn't work.


    Thank you for the contact.