Solved

Context Menus With Listview

Posted on 2004-08-18
6
306 Views
Last Modified: 2008-03-10
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=
0
Comment
Question by:emub
  • 4
  • 2
6 Comments
 

Author Comment

by:emub
ID: 11829775
oCurrentNode is just a (global) "Private oCurrentNode As ListViewItem" on the form
0
 

Author Comment

by:emub
ID: 11829811
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 :(
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 350 total points
ID: 11829819
Instead of using the mousedown use the mouseup event (then it will select the item first)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:emub
ID: 11829846
Ah DOH!,  thx that solved both problems in 1 go dont need that .Slected line in any more :)
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11829855
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
0
 

Author Comment

by:emub
ID: 11829861
Im using a custom control that inherits ListView.  :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now