Search

Problem with TreeView DoubleClick event after expanding/collapsing caused change of scroll by Carlos J. Quintero

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 304958
Opened: 10/16/2007 6:00:32 AM
Access Restriction: Public
1
Workaround(s)
1
User(s) can reproduce this bug
When you double click on a treeview node that has children the node is collapsed or expanded but the subsequent DoubleClick event is not supressed. If the expaning / collapsing causes also a change of scroll, the DoubleClick event is fired when the mouse cursor is on a different treeview node.
Details (expand)
Product Language
English

Version

Visual Studio 2005 (All Products and Editions) Service Pack 1
Operating System
Windows XP Professional
Operating System Language
English
Steps to Reproduce
Create a VS 2005 VB.NET Windows Form application with a TreeView. Add this code:


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Me.TreeView1.Font = New Font("Arial", 8)

Me.TreeView1.Nodes.Add("Node1").Nodes.Add("Node11")

Me.TreeView1.Nodes.Add("Node2").Nodes.Add("Node21")

Me.TreeView1.Height = 40


End Sub


Private Sub TreeView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DoubleClick


Dim objTreeNode As TreeNode


objTreeNode = Me.TreeView1.GetNodeAt(Me.TreeView1.PointToClient(New Point(TreeView.MousePosition.X, TreeView.MousePosition.Y)))


If Not (objTreeNode Is Nothing) Then


If objTreeNode.FirstNode Is Nothing Then ' It's a final node


MessageBox.Show(objTreeNode.Text)


End If


End If

End Sub



The code adds two root nodes with one child node each one. In the DoubleClick event, if the node is final (it has no children), a MsgBox is shown. The height of the treeview is adjusted so only 2 nodes fit: Node1 and Node2, both collapsed.

Now, double click on Node2.




Actual Results
The Node2 is expanded (as expected) but the MsgBox is shown for Node21 as if you double clicked on it, because there was a change of scroll. This caused an unexpected behaviour to the users...
Expected Results
When you double click a tree node with children, the programmer may want one of two things:


- Collapsing/Expanding with no doubleclick event, since no more action is wanted if the semantics for the double click are to expand/collapse

- DoubleClick event with no collapsing/expanding: The user can collapse/expand with the +/- icon and the programmer may want to perform some action on double click rather than expanding/collapsing. There are questions in the forums about how to suppress expanding/collapsing on double click. You can do it overriding some methods but it would be nice to have a property for this.

At the very least (if you don't want to change all this), the collapsing/expanding should not cause a change of scroll, to prevent this bug.
TAP Code (if applicable)
 
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

 

File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 2/2/2009 at 9:19 PM
Thanks for your feedback on the .NET Framework!

We are able to reproduce the bug that you reported and consider rolling in a fix to this issue in next release.

Many customers have found it useful to discuss issues like this in the forums (http://forums.microsoft.com/msdn/default.aspx?siteid=1) where Microsoft and other members of the community can suggest workarounds.

Please keep the feedback comming.

Thanks,
UIFx Team
Posted by IvanKrolo on 1/23/2009 at 9:08 AM
I had the same problem and someone at stackoverflow.com helped me:
http://stackoverflow.com/questions/473113/treeview-double-click-behaviour-in-net-c

So basically don't use e.Node, but use the SelectedNode propery for the actual treeView.
Sign in to post a workaround.
Posted by trolog on 1/4/2011 at 7:49 AM
    Private Sub tvwGroups_AfterExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwGroups.AfterExpand

        If e.Node.Nodes.Count > 0 Then
            tvwGroups.SelectedNode = e.Node.Nodes(0)
        End If

    End Sub

Hope this can help somebody!