Right click select - ListBox

G

Guest

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
 
H

Herfried K. Wagner [MVP]

Art said:
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?

\\\
Private Sub ListBox1_MouseUp( _
ByVal sender As Object, _
ByVal e As MouseEventArgs _:
) Handles ListBox1.MouseUp
If e.Button = MouseButtons.Right Then
Dim n As Integer = Me.ListBox1.IndexFromPoint(e.X, e.Y)
If n <> ListBox.NoMatches Then
Me.ListBox1.SelectedIndex = n

' Show context menu here using 'ContextMenu.Show'...
End If
End If
End Sub
///
 
M

Mike Labosh

If e.Button = MouseButtons.Right Then
Dim n As Integer = Me.ListBox1.IndexFromPoint(e.X, e.Y)
If n <> ListBox.NoMatches Then
Me.ListBox1.SelectedIndex = n

' Show context menu here using 'ContextMenu.Show'...
End If
End If

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.SelectedItems
lstRight.Items.Add(s)
lstLeft.Items.Remove(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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top