|
-
Feb 16th, 2009, 08:47 PM
#1
Thread Starter
^:^...ANGEL...^:^
[2005] [RESOLVED] Prevent TreeNode from Collapsing when DoubleClicked but...
Hi,
I have got a standard Windows Forms Treeview which contains some nodes.
I am using NodeMouseDoubleClick event to get the node and then get the ID of the node and show a form containing data that belongs to the ID.
What I am stuck at is when I double click any node, it Collapses or Expands depending on it's previous state.
I want to Prevent TreeNode from Collapsing or Expanding when DoubleClicked but allow when user clicks that tiny "+" or "-" button in front of the node.
Is this possible? Is so then could someone guide me to the solution please?
Cheers
Last edited by wrack; Feb 16th, 2009 at 09:37 PM.
Reason: [RESOLVED]
-
Feb 16th, 2009, 08:57 PM
#2
Re: [2005] Prevent TreeNode from Collapsing when DoubleClicked but...
The treeview exposes some events for when a node is expanded/collapsed.
Look at the BeforeCollapse and BeforeExpand events
Using the event args in those events you can decide if you want to set e.cancel to true to prevent it from happening.
The solution may include the need to set a boolean variable in your double click code, so you know if you should set cancel to true in these events.
-
Feb 16th, 2009, 09:05 PM
#3
Thread Starter
^:^...ANGEL...^:^
Re: [2005] Prevent TreeNode from Collapsing when DoubleClicked but...
Thanks Kleinma, I tried those but the trouble is when I double click a node, the before collapse event fires before that and thus expanding or collapsing the node and then the double click event happening!
-
Feb 16th, 2009, 09:23 PM
#4
Re: [2005] Prevent TreeNode from Collapsing when DoubleClicked but...
It's not ideal but you could simply undo the operation on a double-click:
vb.net Code:
Private Sub TreeView1_NodeMouseDoubleClick(ByVal sender As Object, _ ByVal e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick If e.Node.IsExpanded Then e.Node.Collapse() Else e.Node.Expand() End If End Sub
Other than that I think you'd have to get into trapping Windows messages to know when the node was expanding or collapsing due to a double-click.
-
Feb 16th, 2009, 09:35 PM
#5
Thread Starter
^:^...ANGEL...^:^
Re: [2005] Prevent TreeNode from Collapsing when DoubleClicked but...
Thanks Jim,
I knew it would come down to this solution, I had it already but I just didn't wanted to go to the WM_Messages path!
I have put this code for now, in C# actually.
Code:
private void tvwChildren_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
string sEntityID = String.Empty;
if (e.Node != null)
{
sEntityID = e.Node.Name.ToString();
}
try
{
tvwChildren.SuspendLayout();
if (e.Node.IsExpanded)
{
e.Node.Collapse();
}
else
{
e.Node.Expand();
}
}
finally
{
tvwChildren.ResumeLayout(true);
}
} // tvwChildren_NodeMouseDoubleClick
Thanks for the heads up.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|