Right click select - ListBox

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

    #1

    Right click select - ListBox

    Hi,

    I've got a bunch of ListBoxes. I want to have a context menu that will
    include, for example, an edit routine. The problem I have is the following.
    Suppose you select item 1. Then you move your mouse to item 9 and right
    click. Item 1 is still selected. Is there any way to have the right click
    select item 9 and then display the context menu?

    As usual... I'd really appreciate any suggestions.

    Thanks,

    Art
  • Herfried K. Wagner [MVP]

    #2
    Re: Right click select - ListBox

    "Art" <Art@discussion s.microsoft.com > schrieb:[color=blue]
    > I've got a bunch of ListBoxes. I want to have a context menu that will
    > include, for example, an edit routine. The problem I have is the
    > following.
    > Suppose you select item 1. Then you move your mouse to item 9 and right
    > click. Item 1 is still selected. Is there any way to have the right
    > click
    > select item 9 and then display the context menu?[/color]

    \\\
    Private Sub ListBox1_MouseU p( _
    ByVal sender As Object, _
    ByVal e As MouseEventArgs _:
    ) Handles ListBox1.MouseU p
    If e.Button = MouseButtons.Ri ght Then
    Dim n As Integer = Me.ListBox1.Ind exFromPoint(e.X , e.Y)
    If n <> ListBox.NoMatch es Then
    Me.ListBox1.Sel ectedIndex = n

    ' Show context menu here using 'ContextMenu.Sh ow'...
    End If
    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

    • Art

      #3
      Re: Right click select - ListBox

      Herfried,

      Thank you very much -- it worked perfectly!

      Art

      "Herfried K. Wagner [MVP]" wrote:
      [color=blue]
      > "Art" <Art@discussion s.microsoft.com > schrieb:[color=green]
      > > I've got a bunch of ListBoxes. I want to have a context menu that will
      > > include, for example, an edit routine. The problem I have is the
      > > following.
      > > Suppose you select item 1. Then you move your mouse to item 9 and right
      > > click. Item 1 is still selected. Is there any way to have the right
      > > click
      > > select item 9 and then display the context menu?[/color]
      >
      > \\\
      > Private Sub ListBox1_MouseU p( _
      > ByVal sender As Object, _
      > ByVal e As MouseEventArgs _:
      > ) Handles ListBox1.MouseU p
      > If e.Button = MouseButtons.Ri ght Then
      > Dim n As Integer = Me.ListBox1.Ind exFromPoint(e.X , e.Y)
      > If n <> ListBox.NoMatch es Then
      > Me.ListBox1.Sel ectedIndex = n
      >
      > ' Show context menu here using 'ContextMenu.Sh ow'...
      > End If
      > End If
      > End Sub
      > ///
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/>
      >
      >[/color]

      Comment

      • Mike Labosh

        #4
        Re: Right click select - ListBox

        > If e.Button = MouseButtons.Ri ght Then[color=blue]
        > Dim n As Integer = Me.ListBox1.Ind exFromPoint(e.X , e.Y)
        > If n <> ListBox.NoMatch es Then
        > Me.ListBox1.Sel ectedIndex = n
        >
        > ' Show context menu here using 'ContextMenu.Sh ow'...
        > End If
        > End If[/color]

        OK, just to go for the gusto, I tried to answer his post using multiselect
        listboxes, and I was doing this:

        For Each s In lstLeft.Selecte dItems
        lstRight.Items. Add(s)
        lstLeft.Items.R emove(s)
        Next

        But it kept barking at me on the Remove line about how you can't remove
        something from this enumerator.

        Not that I care very much, but how would we do the same thing he wants, but
        with multiselect lists?

        --
        Peace & happy computing,

        Mike Labosh, MCSD
        "Working here is like living inside a Salvador Dali painting." -- Me. Yeah,
        ME! [Oh fer cryin out loud]


        Comment

        Working...