I have a TreeView in C# that I am switching on the NodeMouseClick event and opening the appropriate form based on the node clicked which works fine. My question is some of the nodes have children and if you click the little + box next to that node it will expand the tree but it will also select that parent node. I just want it to expand the tree but not select the parent. Have any idea what I'm doing wrong or what I could do?
+1
A:
You can use the following code to in your NodeMouseClick handler to determine if the click occured on the item itself or on the + box. If the result is false, then you can return from the handler without performing your existing action.
bool clickedItem = e.Node.Bounds.Contains(e.Location);
In my test, the selected node is not changed by expanding a node using the + box.
Michael McCloskey
2009-07-27 21:53:25
Worked perfectly thank you.
novacara
2009-07-28 14:41:17
You're welcome.
Michael McCloskey
2009-07-28 14:47:09