Treeview and disabling doubleclick from collapsing/expanding tree

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I would like some advice on how to disable the behavior of treeviews to
expand and collapse when double clicked upon, but still allow the user to use
the plus and minus on each node.

Thanks in advance!
Jack
 
Jack said:
Hello,

I would like some advice on how to disable the behavior of treeviews to
expand and collapse when double clicked upon, but still allow the user to use
the plus and minus on each node.

I can't see the logic in that. Why prevent doubleclicking when
collapsing the tree is allowed?
 
Thanks for the response and it's a good question. I want double-clicking on a
node to open a data entry form regarding that node. So, i'd like to limit
collapsing and expanding nodes to just the plus and minus signs.
 
I haven't tried this but since nobody responded with an answer I'll lay out
my thinking on it.

You need to inherit your own treeview control and then override the double
click handler. I believe if you don't call the mybase function you
shouldn't get the behavior then.

Just an idea.
Chris
 
Hi Jack

I think this is the sort of thing you need. Before expanding or collapsing,
it checks whether you've just double clicked on the control. You'll need to
put your open a form logic into the OnDoubleClick override method as well.
Code follows...

HTH

Nigel Armstrong

Class MyTree
Inherits TreeView

Dim doneByDoubleClick As Boolean = False
Protected Overrides Sub OnDoubleClick(ByVal e As System.EventArgs)
doneByDoubleClick = True
End Sub

Protected Overrides Sub OnBeforeExpand(ByVal e As TreeViewCancelEventArgs)
If doneByDoubleClick Then e.Cancel = True
doneByDoubleClick = False
End Sub

Protected Overrides Sub OnBeforeCollapse(ByVal e As
TreeViewCancelEventArgs)
If doneByDoubleClick Then e.Cancel = True
doneByDoubleClick = False
End Sub
End Class
 
Looks like exactly what I'm looking for. Thanks!

Nigel Armstrong said:
Hi Jack

I think this is the sort of thing you need. Before expanding or collapsing,
it checks whether you've just double clicked on the control. You'll need to
put your open a form logic into the OnDoubleClick override method as well.
Code follows...

HTH

Nigel Armstrong

Class MyTree
Inherits TreeView

Dim doneByDoubleClick As Boolean = False
Protected Overrides Sub OnDoubleClick(ByVal e As System.EventArgs)
doneByDoubleClick = True
End Sub

Protected Overrides Sub OnBeforeExpand(ByVal e As TreeViewCancelEventArgs)
If doneByDoubleClick Then e.Cancel = True
doneByDoubleClick = False
End Sub

Protected Overrides Sub OnBeforeCollapse(ByVal e As
TreeViewCancelEventArgs)
If doneByDoubleClick Then e.Cancel = True
doneByDoubleClick = False
End Sub
End Class
 
Jack -

Did you ever get this to work? I want to do the exact same thing, but I
find that the double-click event happens AFTER the beforeexpand events, so
the example does not work.

-zorpy
 

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

Back
Top