You should be able to use SelectedNode directly - no need to index into the collection. Something like this:
treeView1->SelectedNode->Nodes->Add(...)
How to add a child node to a selected parent node programmatically? C++ Winforms
Friends.
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.
treeView1->Nodes[0]->Nodes->Add(textBox2->Text);
Tks.
-
David Lowndes 4,711 Reputation points
2023-04-02T10:56:10.2233333+00:00
1 additional answer
Sort by: Most helpful
-
José Carlos 886 Reputation points
2023-04-01T19:57:34.92+00:00 Hi Davi,
I used this method inside the parentheses instead of zero, by logic that would be it, but it didn't work.
treeView1->Nodes[treeView1->SelectedNode]->Nodes->Add(textBox2->Text);
Thank you for the contact.