ThreeView

W

Wndr

Hi All.
I have a Treeview with Node1 as parent node, and ChildNode1, ChildNode2,
ChildNode3 for example. When I select any of the ChildNodes and then right
click on it I could easily find what is the Index of the selected Node, but
if I select ParentNode1 and then rightclick on any of the ChildNodes, the
index is still 0. My question is what event should I use, or how can I find
the index of the selected childnode with the RightClick to be able to delete
it for example.
Appreciate any help.
 
N

nnobakht

Hi All.
I have a Treeview with Node1 as parent node, and ChildNode1, ChildNode2,
ChildNode3 for example. When I select any of the ChildNodes and then right
click on it I could easily find what is the Index of the selected Node, but
if I select ParentNode1 and then rightclick on any of the ChildNodes, the
index is still 0. My question is what event should I use, or how can I find
the index of the selected childnode with the RightClick to be able to delete
it for example.
Appreciate any help.

you could just use the treeView_NodeMouseClick and do
private void treeView3_NodeMouseClick(object sender,
TreeNodeMouseClickEventArgs e)
{
treeView3.SelectedNode = e.Node;
}

to select that node first. If you do not do this the index you will
see is for the node that is selected which would be the parent node.

Also the index is not reliable method of accessing nodes or finding
*unique* nodes because two nodes can have the same index.
I recommend using a GUID or some sort of a unique ID which you can
place in the tag.
 
W

Wndr

Thank you so much, it works perfectly.

Hi All.
I have a Treeview with Node1 as parent node, and ChildNode1, ChildNode2,
ChildNode3 for example. When I select any of the ChildNodes and then right
click on it I could easily find what is the Index of the selected Node,
but
if I select ParentNode1 and then rightclick on any of the ChildNodes, the
index is still 0. My question is what event should I use, or how can I
find
the index of the selected childnode with the RightClick to be able to
delete
it for example.
Appreciate any help.

you could just use the treeView_NodeMouseClick and do
private void treeView3_NodeMouseClick(object sender,
TreeNodeMouseClickEventArgs e)
{
treeView3.SelectedNode = e.Node;
}

to select that node first. If you do not do this the index you will
see is for the node that is selected which would be the parent node.

Also the index is not reliable method of accessing nodes or finding
*unique* nodes because two nodes can have the same index.
I recommend using a GUID or some sort of a unique ID which you can
place in the tag.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top