locked
When does a listbox item be selected ? RRS feed

  • Question

  • I have a form with some listboxes.

    I want to extract some info from whichever row the user selects by clicking on the row while holding SHIFT - but I want the clicking of the row to initiate the extraction too !

    For ALL my list boxes the extraction is done the same way and I therefore made my own MouseUp-event Sub like this:

    Private Sub lstBoxMouseUp(clickedLstBox As ListBox, Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = (Shift And acShiftMask) Then If ActiveControl.ItemData(ActiveControl.ItemsSelected.Item(0)) Then <<<<< Run time error 2480

    ' here I do the extraction - and it works nicely !

    End If End If End Sub

    called from each mouseUp-event for each listbox like this:

    Private Sub lstboxName_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
          If Button = (Shift And acShiftMask) Then lstBoxMouseUp ActiveControl, Button, Shift, X, Y
    End Sub

    I get a runtime error 2480 in the marked line !

    I THINK it's because NOTHING is in fact selected - I can verify that in the immidiate window:

    ? ActiveControl.ItemsSelected.Count
     0

    If I switch back to the form, I can SEE the row is black (and therefore selected) !

    What do I misunderstand her ?

    Wednesday, February 6, 2019 11:41 AM

Answers

  • I solved it another way !
    • Marked as answer by Ksor2 Sunday, February 10, 2019 4:32 PM
    Sunday, February 10, 2019 4:32 PM

All replies

  • Hi. How about rather than using ItemData, you just use the column and row index of the listbox for the clicked item?
    Wednesday, February 6, 2019 3:43 PM
  • You're here too ... Hi !

    As a workAround or ... ?

    Why is this _BEEP_ not working ?


    • Edited by Ksor2 Wednesday, February 6, 2019 5:16 PM
    Wednesday, February 6, 2019 5:16 PM
  • Hi. I see what you mean. An index value may not be available yet to be referenced. If so, the only other thought I have is to, somehow, relate the mouse's x-y coordinates with the approximate location of the item row in the listbox.
    Wednesday, February 6, 2019 6:02 PM
  • Hi. I see what you mean. An index value may not be available yet to be referenced. If so, the only other thought I have is to, somehow, relate the mouse's x-y coordinates with the approximate location of the item row in the listbox.

    I can't be that awkward ... one should easily get some infos out from a the clicked row WITHOUT X coordinate !

    It CAN*T be made that way by design !

    Sunday, February 10, 2019 2:47 PM
  • I solved it another way !
    • Marked as answer by Ksor2 Sunday, February 10, 2019 4:32 PM
    Sunday, February 10, 2019 4:32 PM
  • I solved it another way !

    Hi Ksor2,

    I don't use List boxes, so I cannor comment on that.

    But for Text boxes, I save the selected value in a global string on exit of the control. As I use generalised functionaity, this holds for every control on every form (in any application).

    Imb.

    Sunday, February 10, 2019 6:32 PM
  • I solved it another way !

    Hi. Congratulations! Please consider sharing your solution so others might benefit as well. Good luck!
    Monday, February 11, 2019 3:54 PM