TreeView control node selection
-
Hi, I'm using Visual Studio 2005 C++/CLI. I have a TreeView Control that displays a few nodes with some sub-nodes in each. I have written the application so if I right click on a sub-node I get a ContextMenuStrip where I can select "MenuItem". If I left click on a sub-node FIRST (thus selecting the node) then right click to select "MenuItem", I can then use... TreeNode^ selectedNode = this->treeViewInstruments->SelectedNode; ...to get a copy of the selected node. However, if I DO NOT left click on the sub-node first and simply right click on it and then select "MenuItem" the above line of code returns an undefined value. I added code to respond to the mouse right click on a node but I can't seem to set the node as selected. I just want to be able to "set the node I just right clicked on to the selected node". Thanks Buck
-
Hi, I'm using Visual Studio 2005 C++/CLI. I have a TreeView Control that displays a few nodes with some sub-nodes in each. I have written the application so if I right click on a sub-node I get a ContextMenuStrip where I can select "MenuItem". If I left click on a sub-node FIRST (thus selecting the node) then right click to select "MenuItem", I can then use... TreeNode^ selectedNode = this->treeViewInstruments->SelectedNode; ...to get a copy of the selected node. However, if I DO NOT left click on the sub-node first and simply right click on it and then select "MenuItem" the above line of code returns an undefined value. I added code to respond to the mouse right click on a node but I can't seem to set the node as selected. I just want to be able to "set the node I just right clicked on to the selected node". Thanks Buck
Sorry, I didn't get you... Are you trying to select a tree item using the right click?
- NS - [ODBaseBtn]
-
Hi, I'm using Visual Studio 2005 C++/CLI. I have a TreeView Control that displays a few nodes with some sub-nodes in each. I have written the application so if I right click on a sub-node I get a ContextMenuStrip where I can select "MenuItem". If I left click on a sub-node FIRST (thus selecting the node) then right click to select "MenuItem", I can then use... TreeNode^ selectedNode = this->treeViewInstruments->SelectedNode; ...to get a copy of the selected node. However, if I DO NOT left click on the sub-node first and simply right click on it and then select "MenuItem" the above line of code returns an undefined value. I added code to respond to the mouse right click on a node but I can't seem to set the node as selected. I just want to be able to "set the node I just right clicked on to the selected node". Thanks Buck
Hey Buck, I have not got around to doing this with the .NET TreeView yet but I had to deal with it in MFC years ago so it should translate. In my OnContextMenu handler I used the tree control HitTest() to discover the node that was clicked on. I see in the BCL TreeView documentation it has a HitTest() method. I don't know if translating the point would still apply in the .NET environment in that it might already be done.
void CEdTree::OnContextMenu(CWnd*, CPoint point)
{
CPoint pt(point);
ScreenToClient(&pt);
_nmRClickItem = tree().HitTest(pt); -
Hey Buck, I have not got around to doing this with the .NET TreeView yet but I had to deal with it in MFC years ago so it should translate. In my OnContextMenu handler I used the tree control HitTest() to discover the node that was clicked on. I see in the BCL TreeView documentation it has a HitTest() method. I don't know if translating the point would still apply in the .NET environment in that it might already be done.
void CEdTree::OnContextMenu(CWnd*, CPoint point)
{
CPoint pt(point);
ScreenToClient(&pt);
_nmRClickItem = tree().HitTest(pt);