Hello

I have created a windows forms application that has a windows explorer style
interface using a TreeView and a ListView, I have attached a ContextMenuStrip to
the tree view which appears when the user right clicks on a node. I would like
to mimic the behaviour of the tree view of the windows explorer so that even
though the user might have selected a node already, when they right click a
different node the node they have right clicked on will appear to be selected
while the context menu is displayed, how can I do this?

Thanks

Alex

Re: Explorer style interface by Otis

Otis
Sat Feb 04 12:25:20 CST 2006

On Sat, 4 Feb 2006 13:26:24 -0000, "Alexander Walker"
<alex@noemail.noemail> wrote:

>Hello
>
>I have created a windows forms application that has a windows explorer style
>interface using a TreeView and a ListView, I have attached a ContextMenuStrip to
>the tree view which appears when the user right clicks on a node. I would like
>to mimic the behaviour of the tree view of the windows explorer so that even
>though the user might have selected a node already, when they right click a
>different node the node they have right clicked on will appear to be selected
>while the context menu is displayed, how can I do this?
>
>Thanks
>
>Alex
>
>
>
>
If you are using VS 2005 (.NET 2.0) then do this:

private void treeView1_NodeMouseClick(object sender,
TreeNodeMouseClickEventArgs e)
{
if (e.Node.IsSelected == false && e.Button ==
MouseButtons.Right)
{
((TreeView)sender).SelectedNode = e.Node;
}
}

If not you will need to capture the MouseClick event and get the node
from the mouse's x, y position and set the clicked node from that.


Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com