Home All Groups Group Topic Archive Search About

Context Menu Not Closing

Author
4 Dec 2006 1:43 PM
Fred
Hi,

I have a list box with a context menu.  When I right click the menu
appears as expected.  However when I select an option on the context
menu the menu does not close.  The click event on the menu is fired but
the menu remains.

Is there anyway I can get this menu to close when I select a menu
option?

Ive tried setting the ContextMenu property of the list box to nothing
but the menu remains :(

Its not until I click elsewhere that the menu disappears.

Thanks for any help

Fred

Author
4 Dec 2006 3:37 PM
NickP
Hi there,

    Can you should the code you are using to make the context menu appear
please....

    If it's in an event could you copy and paste the entire event please,
that would be helpful.

Nick.

Show quoteHide quote
"Fred" <f***@fredthomas.co.uk> wrote in message
news:1165239835.449872.316880@80g2000cwy.googlegroups.com...
> Hi,
>
> I have a list box with a context menu.  When I right click the menu
> appears as expected.  However when I select an option on the context
> menu the menu does not close.  The click event on the menu is fired but
> the menu remains.
>
> Is there anyway I can get this menu to close when I select a menu
> option?
>
> Ive tried setting the ContextMenu property of the list box to nothing
> but the menu remains :(
>
> Its not until I click elsewhere that the menu disappears.
>
> Thanks for any help
>
> Fred
>
Author
4 Dec 2006 3:41 PM
Fred
Just in case anyone else gets this problem ......

I changed the code and it all works fine now.

Instead of setting the Context menu at Design time I do it all at
runtime.....


Private Sub lstStaff_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstStaff.MouseUp
        If e.Button = MouseButtons.Right Then

                    lstStaff.ContextMenu = Me.mnuPopup
                    lstStaff.ContextMenu.Show(lstStaff, New Point(e.X,
e.Y))
                    lstStaff.ContextMenu = Nothing
         End If
End Sub



Fred


Fred wrote:
Show quoteHide quote
> Hi,
>
> I have a list box with a context menu.  When I right click the menu
> appears as expected.  However when I select an option on the context
> menu the menu does not close.  The click event on the menu is fired but
> the menu remains.
>
> Is there anyway I can get this menu to close when I select a menu
> option?
>
> Ive tried setting the ContextMenu property of the list box to nothing
> but the menu remains :(
>
> Its not until I click elsewhere that the menu disappears.
>
> Thanks for any help
>
> Fred
Author
4 Dec 2006 3:47 PM
NickP
Thanks for posting an update, good to hear you got it sorted.

Nick.

Show quoteHide quote
"Fred" <f***@fredthomas.co.uk> wrote in message
news:1165246915.955688.244340@73g2000cwn.googlegroups.com...
> Just in case anyone else gets this problem ......
>
> I changed the code and it all works fine now.
>
> Instead of setting the Context menu at Design time I do it all at
> runtime.....
>
>
> Private Sub lstStaff_MouseUp(ByVal sender As Object, ByVal e As
> System.Windows.Forms.MouseEventArgs) Handles lstStaff.MouseUp
>        If e.Button = MouseButtons.Right Then
>
>                    lstStaff.ContextMenu = Me.mnuPopup
>                    lstStaff.ContextMenu.Show(lstStaff, New Point(e.X,
> e.Y))
>                    lstStaff.ContextMenu = Nothing
>         End If
> End Sub
>
>
>
> Fred
>
>
> Fred wrote:
>> Hi,
>>
>> I have a list box with a context menu.  When I right click the menu
>> appears as expected.  However when I select an option on the context
>> menu the menu does not close.  The click event on the menu is fired but
>> the menu remains.
>>
>> Is there anyway I can get this menu to close when I select a menu
>> option?
>>
>> Ive tried setting the ContextMenu property of the list box to nothing
>> but the menu remains :(
>>
>> Its not until I click elsewhere that the menu disappears.
>>
>> Thanks for any help
>>
>> Fred
>
Author
4 Dec 2006 4:41 PM
Fred
Nothing more frustrating than seeing someone else post the same problem
you've got but no follow up posts to say how it was solved! ;)

I discovered that setting a context menu at design time brought about a
few problems.

1. The menu did not disappear on click of a menu option.
2. Although I had the ContextMenu.Show in the MouseUp event it was
showing on the mouse down :s
3. I put a trap on the ListView selected Items property to say "don't
show the menu if nothing is selected" which it totally ignored!

All seemed strange to me but im sure there is some logic in there
somewhere!!

Thanks for responding though Nick.

Fred

NickP wrote:
Show quoteHide quote
> Thanks for posting an update, good to hear you got it sorted.
>
> Nick.
>
> "Fred" <f***@fredthomas.co.uk> wrote in message
> news:1165246915.955688.244340@73g2000cwn.googlegroups.com...
> > Just in case anyone else gets this problem ......
> >
> > I changed the code and it all works fine now.
> >
> > Instead of setting the Context menu at Design time I do it all at
> > runtime.....
> >
> >
> > Private Sub lstStaff_MouseUp(ByVal sender As Object, ByVal e As
> > System.Windows.Forms.MouseEventArgs) Handles lstStaff.MouseUp
> >        If e.Button = MouseButtons.Right Then
> >
> >                    lstStaff.ContextMenu = Me.mnuPopup
> >                    lstStaff.ContextMenu.Show(lstStaff, New Point(e.X,
> > e.Y))
> >                    lstStaff.ContextMenu = Nothing
> >         End If
> > End Sub
> >
> >
> >
> > Fred
> >
> >
> > Fred wrote:
> >> Hi,
> >>
> >> I have a list box with a context menu.  When I right click the menu
> >> appears as expected.  However when I select an option on the context
> >> menu the menu does not close.  The click event on the menu is fired but
> >> the menu remains.
> >>
> >> Is there anyway I can get this menu to close when I select a menu
> >> option?
> >>
> >> Ive tried setting the ContextMenu property of the list box to nothing
> >> but the menu remains :(
> >>
> >> Its not until I click elsewhere that the menu disappears.
> >>
> >> Thanks for any help
> >>
> >> Fred
> >