Results 1 to 2 of 2

Thread: [2005] Get listbox item that was right clicked?

  1. #1

    Thread Starter
    Hyperactive Member cptHotkeys's Avatar
    Join Date
    Apr 2007
    Location
    New Zealand
    Posts
    294

    [2005] Get listbox item that was right clicked?

    Hi, does anyone know how to get which item in a listbox was just right clicked, I need the index not the string as there are duplicates and I need to reference a corresponding item in a list(of string) at the same (by index, not value)...
    I would like to be able to select an Item with right click too...
    At the moment all I can do is find which button was pressed in a mouse event using
    Code:
    If e.button = mousebuttons.right then
        'Now here is the problem
        dim i as integer
        'i should = lstbox.selectedindex
    Elseif e.button = mousebuttons.left then
    End if
    Also, after setting multi select (I tried both versions) and selecting / highlighting multiple files, a for each loop does not use all selected items?
    Does anyone know why this would happen, my code is simple, I use shift and click to select multiple files... and use a loop like below in a context menu button, could this be because i right click after selecting items?
    Code:
    for each i as integer in listbox1.selectedIndicies
        'Not all items I highlighted are coming through...
        'This makes me think that a highlighted Item is not nececarily selected.
        'Is there some othre methods availabe for this? (finding highlited items)
        'This is for removing items from the list...
    next
    One more thing, I am about to implement drag and drop in a list view for the first time (no other controls involved, just letting the user reorder the list items) and any advice would be greatly appreciated...

    Thanks in advance...

    Documentation didnt help and neither did big G.
    Last edited by cptHotkeys; Jun 24th, 2007 at 02:29 AM.

    Signatures suck

  2. #2

    Thread Starter
    Hyperactive Member cptHotkeys's Avatar
    Join Date
    Apr 2007
    Location
    New Zealand
    Posts
    294

    Re: [2005] Get listbox item that was right clicked?

    I resolved the selecting by right click...
    But I still need help with multi select...

    any way here is the code
    Code:
    Private Sub lbNames_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbNames.MouseDown
        If e.Button = MouseButtons.Right Then
            'IF the select item count is more than one dont select the one that was clicked.
            If lbNames.selectedItems.count <= 1 then
                Dim pt As New Point(e.x,e.y)
                lbNames.SelectedIndex = lbNames.IndexFromPoint(pt)
            end if
        End If
    End Sub

    Signatures suck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width