Solved

Context Menus With Listview

Posted on 2004-08-18
6
303 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

20 Experts available now in Live!

Get 1:1 Help Now