Results 1 to 3 of 3

Thread: stuck: cant move to another TreeNode by rightclicking

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    stuck: cant move to another TreeNode by rightclicking

    I want to be able to change the selected node of a treeView by rightclicking on it, but seems like I cant do it.

    the very odd thing is that when you right click on a node, it is highlighted as long as you dont release the mouse button. If you release the mouse button, the focus goes back to the last node.

    I'm probably doing something really wrong, but whatever I'm doing, I cant figure it out. I even started a new project just to test and see if this would happen to another project, but same problem.

    some help is appreciated
    (If you're wondering why I want to do this: when the user right-clicks on an item, I want that item to be selected and then I want a popup menu to be shown. But TreeView.SelectedNode doesnt point to the right node at the time of the right click, nor after it )
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Weird , it's working here .
    VB Code:
    1. Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
    2.         If e.Button = MouseButtons.Right Then
    3.             MsgBox(Me.TreeView1.SelectedNode.Text)
    4.         End If
    5.     End Sub
    Attached Images Attached Images  

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    copy pasted your code in a new project with only a treeview. no it doesnt work.... try this with the same code:

    when you run the program, let one of the nodes be selected, then rightclick on ANOTHER node. I want the messagebox to show the name of the node that you just rightclicked...


    right now I'm doing something like this: I have a TreeView_MouseUp event. I check the x and y coordinate of the mouseclick and with TreeView.GetNodeAt(x,y) I figure out which node was clicked. (and I also have to manually set that node to TreeView.SelectedNode )

    VB Code:
    1. Private Sub tvwItems_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwItems.MouseUp
    2.         If (e.Button = MouseButtons.Right) Then
    3.             Dim aNode As TreeNode = tvwItems.GetNodeAt(e.X, e.Y)
    4.             tvwItems.SelectedNode = aNode
    5.             cmnuItem.Show(tvwItems, New Point(e.X, e.Y))
    6.         End If
    7.     End Sub
    well it works now but it seems redundant. I feel like I'm missing something here
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width