Link to home
Start Free TrialLog in
Avatar of emub
emubFlag for United Kingdom of Great Britain and Northern Ireland

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.MouseEventArgs) 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=
Avatar of emub
emub
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

oCurrentNode is just a (global) "Private oCurrentNode As ListViewItem" on the form
Avatar of emub

ASKER

Hi,

Sorry I solved the first problem with addeding

Me.Items(oCurrentNode.Index).Selected = True

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
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of emub

ASKER

Ah DOH!,  thx that solved both problems in 1 go dont need that .Slected line in any more :)
Avatar of RonaldBiemans
RonaldBiemans

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.MouseEventArgs) Handles MyBase.MouseDown

shouldn't it be

   Private Sub listmenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles listmenu.MouseDown
Avatar of emub

ASKER

Im using a custom control that inherits ListView.  :)