Listbox Click event

Discussion in 'AutoCAD' started by MickyV, Aug 10, 2004.

  1. MickyV

    MickyV Guest

    I've got a listbox that I want to fire a new dialog box from when a particular item is picked. At the moment, I've used the Click event, but it won't fire if the item is already selected (i've got it retaining the last value).

    Does anyone know a way around this, so it picks up every click, even though the listbox hasn't changed?

    Thanks,
    Mick.

    Example:-
    Private Sub listbox1_Click()

    Select Case listbox1.ListIndex

    Case 0
    'do stuff
    Case 1
    'do other stuff
    Case 2
    'do other stuff
    Case 3
    'do other stuff

    End Select

    End Sub
     
    MickyV, Aug 10, 2004
    #1
  2. MickyV

    Joe Sutphin Guest

    The Click fires when you click on an item or when you set the ListIndex
    property to be an item in the list.
    Also, you could use the Enter and Exit events accordingly or the Change
    event. It's all about timing.

    Joe
    --

    particular item is picked. At the moment, I've used the Click event, but it
    won't fire if the item is already selected (i've got it retaining the last
    value).
    though the listbox hasn't changed?
     
    Joe Sutphin, Aug 10, 2004
    #2
  3. What about when your form initializes. Do a check then, seeing you retain
    last value.

    --

    Thanks,

    David M. Gardner
    Change the DOT to reply.
     
    David M. Gardner, Aug 10, 2004
    #3
  4. MickyV

    aks01 Guest

    I use the Change event, but I use it with a mode flag that is checked by code in the Change event to ignore the times when the Change event fires (like adding an item for example) where I don't want the list to react as if someone has selected an item.
     
    aks01, Aug 10, 2004
    #4
  5. MickyV

    MickyV Guest

    The problem is that if the item is already selected, the Click event doesn't fire unless the user changes it, then changes it back.

    I don't want to run my procedure when the form initializes, because I want to give the user a chance to change the selection.

    I can't use the Change event, because it won't fire if the item is already sleected, then the user reselects it, and when I try to use the Exit event, I get a compile error "Procedure declaration does not match description of event or procedure having the same name"

    Oh, and I'm using a ComboBox, not a ListBox. Sorry about that.
     
    MickyV, Aug 11, 2004
    #5
  6. MickyV

    bcoward Guest

    Micky,

    If I'm reading this correctly your wanting to set the listindex of the listbox in a way that will supercede the click event.

    If this is your interest then use the Send Message API using SetListIndex


    Public Declare Function SendMessage _
    Lib "user32" _
    Alias "SendMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) _
    As Long

    Function SetListIndex(lst As Control, ByVal NewIndex As Long) As Long

    Const CB_GETCURSEL = &H147
    Const CB_SETCURSEL = &H14E
    Const LB_GETCURSEL = &H188
    Const LB_SETCURSEL = &H186

    If TypeOf lst Is ListBox Then
    Call SendMessage(lst.hwnd, LB_SETCURSEL, NewIndex, 0&)
    SetListIndex = SendMessage(lst.hwnd, LB_GETCURSEL, NewIndex, 0&)
    ElseIf TypeOf lst Is ComboBox Then
    Call SendMessage(lst.hwnd, CB_SETCURSEL, NewIndex, 0&)
    SetListIndex = SendMessage(lst.hwnd, CB_GETCURSEL, NewIndex, 0&)
    End If

    End Function

    To use just add this line and change YourListBox to the listbox your wanting to suprcede the click event. As you can see it will also work for combo box class objects.
    :

    Dim TT as Long
    TT = SetListIndex(YourListBox, 0)


    Good luck,

    Bob Coward
    CADS, Inc

    www.cadsinc.com
    800-366-0946

     
    bcoward, Aug 11, 2004
    #6
  7. MickyV

    MickyV Guest

    Hi Bob,

    That's not really what I'm after. I just want the click event to fire when the user click the already-selected item.

    Mick.
     
    MickyV, Aug 11, 2004
    #7
  8. MickyV

    bcoward Guest

    oops
     
    bcoward, Aug 12, 2004
    #8
  9. MickyV

    MickyV Guest

    I figured out a way around it.

    I've trapped the MouseUp event, checking for the ListIndex that I'm after, then triggering the Click event from there.
     
    MickyV, Aug 12, 2004
    #9
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 (here). After that, you can post your question and our members will help you out.