Context Menu question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J L

    #1

    Context Menu question

    I have a form with a listview on it and a context menu. I handle the
    right click event on the listview but after handling the event, the
    context menu then appears. I would like to disable it if the user
    right clicks on an item in the listview. I do like it to appear if the
    user right clicks on an empty part of the listview.

    Can this be done? If so how?

    TIA
    John
  • Pipo

    #2
    Re: Context Menu question

    Hi J L,

    In mousedown event of the listview:

    Dim blnState As Boolean = (e.Button = MouseButtons.Ri ght) AndAlso
    (ListView1.Sele ctedItems.Count > 0)

    mnuAdd.Visible = blnstate

    mnuRemove.Visib le = blnstate


    "J L" <john@marymonte .com> wrote in message
    news:emkn91hi84 e3kgouitjvrd378 qodbiu2je@4ax.c om...[color=blue]
    > I have a form with a listview on it and a context menu. I handle the
    > right click event on the listview but after handling the event, the
    > context menu then appears. I would like to disable it if the user
    > right clicks on an item in the listview. I do like it to appear if the
    > user right clicks on an empty part of the listview.
    >
    > Can this be done? If so how?
    >
    > TIA
    > John[/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Context Menu question

      "J L" <john@marymonte .com> schrieb:[color=blue]
      >I have a form with a listview on it and a context menu. I handle the
      > right click event on the listview but after handling the event, the
      > context menu then appears. I would like to disable it if the user
      > right clicks on an item in the listview. I do like it to appear if the
      > user right clicks on an empty part of the listview.[/color]

      \\\
      Private Sub ListView1_Mouse Up( _
      ByVal sender As Object, _
      ByVal e As MouseEventArgs _
      ) Handles ListView1.Mouse Up
      Dim i As ListViewItem = Me.ListView1.Ge tItemAt(e.X, e.Y)
      If i Is Nothing Then
      Me.ContextMenu1 .Show(...)
      End If
      End Sub
      ///

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • J L

        #4
        Re: Context Menu question

        Thank you both. Exactly what I needed.

        John

        On Tue, 31 May 2005 11:13:52 +0200, "Herfried K. Wagner [MVP]"
        <hirf-spam-me-here@gmx.at> wrote:
        [color=blue]
        >"J L" <john@marymonte .com> schrieb:[color=green]
        >>I have a form with a listview on it and a context menu. I handle the
        >> right click event on the listview but after handling the event, the
        >> context menu then appears. I would like to disable it if the user
        >> right clicks on an item in the listview. I do like it to appear if the
        >> user right clicks on an empty part of the listview.[/color]
        >
        >\\\
        >Private Sub ListView1_Mouse Up( _
        > ByVal sender As Object, _
        > ByVal e As MouseEventArgs _
        >) Handles ListView1.Mouse Up
        > Dim i As ListViewItem = Me.ListView1.Ge tItemAt(e.X, e.Y)
        > If i Is Nothing Then
        > Me.ContextMenu1 .Show(...)
        > End If
        >End Sub
        >///[/color]

        Comment

        Working...