Select Node in TreeView with MouseButtons.Right ...

  • Thread starter Joerg Trumpfheller
  • Start date
J

Joerg Trumpfheller

Hey people,

how can I select a treenode with the MouseButtons.Right event if there is no
contextmenu?

I build up a treeview with 3 levels. Only if the second level is selected,
there should be a contextmenu.
This works without problems. In between this level I can select the next
node with the mouseButtons.Right because there is a contextmenu.
If I try to select a node of the first or third level , it gets selected by
holding the mousedown, but with mouseup it jumps back to the origin.
Is there a possibility to handle this?

Greetings Joerg
 
G

Gette

Can you please post the code so I can look at it.
I think that you have used the wrong events.
 
J

Joerg Trumpfheller

Hy Gette,

sorry for late answering but I was illl
Gette said:
Can you please post the code so I can look at it.
I think that you have used the wrong events.

Here is the code
' Declare an event at module level of a class module

Event getSelectedNode(ByVal Pos1 As Integer, ByVal Pos2 As Integer)

Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) _

Handles TreeView1.MouseDown

If MouseButtons = MouseButtons.Right Then

Dim node As TreeNode = TreeView1.GetNodeAt(e.X, e.Y)

Dim selNode As TreeNode = TreeView1.SelectedNode

' Update the context menu text here

'MsgBox(node.ImageIndex)

' there are Icons for the nodes, so I can make decicions for which icon
(level) should be a context menu

If (node.ImageIndex = 2) Then

Me.TreeView1.ContextMenu = Me.TreeViewContextMenu

Else

Me.TreeView1.ContextMenu = Nothing

Dim aa, bb As Boolean

aa = node.Checked

bb = node.IsSelected

Debug.WriteLine(selNode.ToString() & " - " & node.ToString())

'MsgBox(node.ImageIndex & " - Checked(?):" & aa & " - " & node.FullPath _

'& " - " & node.Index & " - IsSelected(?):" & bb & " - " _

'& node.SelectedImageIndex & " - " & selNode.ToString())

RaiseEvent "here should be a routine, which fires the MouseButton.Left event
for that position"(e.X, e.Y)

End If

End If

End Sub



Thanks for help Joerg
 

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

Top