Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
:doh:
I have on my form a TreeView with a lots of items/nodes. When I double click a item of a node I run a procedure (depending of the clicked item).My problem is that I want it to expand/collapse only when I click on the icon of the node ( the + or - sign), not if I double click an item
Posted
Comments
Sergey Alexandrovich Kryukov 27-Jan-11 23:13pm    
Click is not the only way to expand/collapse - you also do it via keyboard. Want to disable it, too? I don't recommend any of these modifications of expected UI behavior.
--SA
gksdy2000 27-Jan-11 23:29pm    
I know method that treeNode.Expand(), treeNode.Collapse()

but When click event occurred.
Whether event was produced at node or was produced in image, I don't know

Hi,

In your double click event forced to collapse the selected TreeNode..

For ex:

In NodeMouseDoubleClick event write the following code..
TreeNode trNode = (TreeNode)e.Node;
trNode.Collapse();


Try this..

Cheers:)
 
Share this answer
 
v2
Comments
gksdy2000 28-Jan-11 3:42am    
reply Thank.
But If do so, node is expanded after collapsed. ^^
VB
Private Sub tv1_NodeMouseClick(sender As Object, e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tv1.NodeMouseClick
  If e.X < e.Node.Bounds.Left Then
    Debug.Print("Img Click")
  Else
    Debug.Print("Txt Click")
  End If
End Sub


The e.X is the X-coordinate (horizontal position) of the mouse click. the e.Node.Bounds is the bounds (left/right/height/width) of the node text. So if the X coordinate is less than the node text bounds left-most position, the click occurred in the image area (to the left) of the node.
 
Share this answer
 
Check the TreeView NodeMouseClick event
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
 
Share this answer
 
Comments
gksdy2000 27-Jan-11 23:19pm    
Already I Checked the TreeView NodeMouseClick eventWhen clicked, whether it is that is clicked at node or it is that is clicked in image, it is no to distinguish.Is no there solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900