views:

362

answers:

3

Hi, I would need to know how to let the programatically selected node make graphically in the state "selected" like the user clicked on it. SelectedNode only makes this one internally selected. Thank you very much!

A: 

Not sure, but can you not change the background color of that node?

theraneman
That would be problematical, I would need to ensure its set back when other node is selected etc.
Petr
That also seems very hacky.
Pondidum
A: 

The reason it does not show as highlighted is due to the tree view not having focus. This is in a button click event on my test form:

TreeView1.SelectedNode = TreeView1.Nodes(2);
TreeView1.Focus();

Which highlights the node properly. if you remove the Focus(); call it doesn't highlight until you click into the tree view (anywhere in the tree view, not necessarily on to the node that you want to be selected).

Pondidum
Also the property HideSelection can be used. If set to false the highlight will be shown regardless of focus.
Goran
A: 

The underlying Win32 control supports this (think it's TVIS_DROPHILITED), but I can't see the same functionality exposed through the TreeView control.

As theraneman says, you could fake it with the TreeNode.ForeColor and BackColor properties...

Tim Robinson