Search code examples
treeviewtreenodeselectedindex

Assigning TreeNode to TreeView and show as selected


HI,

I have TreeNode trn which is containing treenode with some of its child nodes. Now i want to pass this node to TreeView tree from another method and i want to the show the trn as selected tree node in the TreeView tree.

(trn is likely to change every time as per the selection by user)

I have tried using

tree.SelectedNode = trn;

but it is giving me absurd result like sometimes highlighting another node or sometimes highlighting the Root node only etc.

Do we have indexes for treeNode so if i get index of any node so i will just use

tree.SelectedIndex = index; 

But i am not sure that SelectedIndex really exists for TreeNode ?

Any help

Regards,

Sangram Nandkhile


Solution

  • try this one.

    tree.select();
    tree.SelectedNode = trn;