Results 1 to 5 of 5
  1. #1
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Multi Select List Box (2000)

    If a listbox control has its multi-select propert set to Simple,
    Is there any way of knowing which was the last selected item when more than one is selected?
    I don't mean the last in the selected list, I mean the last one clicked on.
    I need to have multi-select for one process but also need to determine the last clicked on entry.
    So suppose I have a list of 10 items in a list box control called lstItems, and They are clicked on in this order from Top to Bottom.

    Item 2
    Item 7
    Item 4

    So 2, 4 and 7 where selected in the list
    Is there any way to tell that Item 4 was the last selected one.

    I have looked at itemdata and itemsselected but neither seem to give the info I want.

    If I cannot get round this I will have to find an alternative route which would be a shame.
    Andrew

  2. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Multi Select List Box (2000)

    I was being silly on 2 counts here.

    1.
    The information can be extracted using the Column Property
    (This was also a multi column list box).

    lstItems.Column(colNo) returns information from the last selected row so my main problem is solved.

    2
    I should have also said that I was interested in retrieving the row number of the last row as well.

    This is harder and possible impossible unless one of the columns of the list box is Unique.
    Assuming this is the case, then the following example might assist others


    Suppose that Column 3 (Index 2) of the list box had the unique entry

    Then something like

    strID=lstItems.Column(2)

    will retrieve the Unique Value

    If we are interested in determining the last Selected Item then we can use

    For Each varItem In lstItems.ItemsSelected
    If lstItems.Column(2,varItem)=strID then
    intRow=varItem
    End If
    Next

    If this returns 0 then the Row clicked is NOT in the selected List.

    To find out which entry in the list it actually is we would need to check all List box items

    For intItem = 0 to lstItems.ListCount-1
    If lstItems.Column(2,intItem)=strID Then
    intRow=intItem
    EndIf
    Next

    Remembering that Items Also start their count from 0

    Well, it works for me anyway.

    Anyone has a better solution then let me know.
    Anything to make life easier.
    Andrew

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Multi Select List Box (2000)

    Be careful! If the user selects items, then unselects one or more of them, there is no way of knowing which of the items that remain selected is the most recent one.

    The ListIndex property of the list box returns the zero-based row number of the most recently clicked item, but this item could have been selected or unselected.

  4. #4
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Multi Select List Box (2000)

    Fortunately I did not need that information.
    Only needed to know which one was last clicked on.
    Then the check to see if it is in the selected list tells me if it was just selected or not.

    As far as I can see, there is NO way to know which one was last selected
    in ther selected list when one is de-selected, other than run another Hidden list box or a Public Collection in VBA rather which keeps another list in the order of selection and removes and adds items from/to it, so that the last one in it was always the last selected.
    But that is a load of programming overhead unless it was really necessary to know that.

    Luckily I don't have to.
    Andrew

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Multi Select List Box (2000)

    OK, that's fine. If you only need to know the index of the most recently clicked item, you can use the ListIndex property. It's zero based, it runs from 0 to ListCount - 1.

Posting Permissions

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