Explorer style interface

  • Thread starter Alexander Walker
  • Start date
A

Alexander Walker

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
 
O

Otis Mukinfus

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
 

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