emub
asked on
Context Menus With Listview
Hi,
Im just trying to tidyup the user interface for the listview on my form. The problem that im having is, I would like when the users RightClicks on a listviewItem for it to selcted(highlight) it fist before bringing up the contextmenu.
Also
While the contextmenu is displayed I have another anoying bug where if you click anywhere else on the form the contextmenu disapears and reapears very quickly so to make a contextmenu go away without selecting a option from it you have to efectivly click twice anywhere on the form :(
[Code Im using to display the contextmenu on the listview]
Private Sub listmenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles MyBase.MouseDown
oCurrentNode = sender.GetItemAt(e.X, e.Y)
'If Right mouse button is pressed
If e.Button = MouseButtons.Right Then
If Not Me.ContextMenu Is Nothing Then
Me.ContextMenu.Show(Me, New Point(e.X, e.Y))
End If
End If
End Sub
Regards
=Daniel=
Im just trying to tidyup the user interface for the listview on my form. The problem that im having is, I would like when the users RightClicks on a listviewItem for it to selcted(highlight) it fist before bringing up the contextmenu.
Also
While the contextmenu is displayed I have another anoying bug where if you click anywhere else on the form the contextmenu disapears and reapears very quickly so to make a contextmenu go away without selecting a option from it you have to efectivly click twice anywhere on the form :(
[Code Im using to display the contextmenu on the listview]
Private Sub listmenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
oCurrentNode = sender.GetItemAt(e.X, e.Y)
'If Right mouse button is pressed
If e.Button = MouseButtons.Right Then
If Not Me.ContextMenu Is Nothing Then
Me.ContextMenu.Show(Me, New Point(e.X, e.Y))
End If
End If
End Sub
Regards
=Daniel=
ASKER
Hi,
Sorry I solved the first problem with addeding
Me.Items(oCurrentNode.Inde x).Selecte d = True
before displaying the contextmenu.
but the second problem is insits on having to click twice anywhere to get rid of the contextmenu :(
Sorry I solved the first problem with addeding
Me.Items(oCurrentNode.Inde
before displaying the contextmenu.
but the second problem is insits on having to click twice anywhere to get rid of the contextmenu :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah DOH!, thx that solved both problems in 1 go dont need that .Slected line in any more :)
you are using mybase.mouse down which is the mousedown event of the form or are you using a custom listview control ?
Private Sub listmenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles MyBase.MouseDown
shouldn't it be
Private Sub listmenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles listmenu.MouseDown
Private Sub listmenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
shouldn't it be
Private Sub listmenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
ASKER
Im using a custom control that inherits ListView. :)
ASKER