ItemData question

Marko Stojovic

Registered User.
Local time
Today, 12:27
Joined
Jan 25, 2001
Messages
29
Hello,

I'm getting really confused... I have a listbox which allows multiple selections. The listbox is called "lstResultList".

I'm trying to use this code (it's in an OnClick event in the form that has the listbox in it...):

If Me.lstResultList.ItemsSelected.Count > 0 Then
For m = 0 To Me.lstResultList.ItemsSelected.Count - 1
MsgBox Me.lstResultList.ItemData(m)
Next m
End If

Actually, I was trying to do something a bit more complex to start with, but I narrowed down the problem to this part. When I execute it, it stops on the MsgBox line, because it always evaluates Me.lstResultList.Itemdata(m) to NULL! At the same time, "?Me.lstResultList.ItemsSelected.Count" shows how many menu items have been highlighted, as expected. This really confuses me.

Does anyone have a clue why the programme might be recognising ItemData as Null for each of the items in the ItemsSelected collection for the control, even though the list box shows string values listed, lets me highlight a number of them, and has recognised them as highlighted?

Thanks in advance for easing my agony,

Marko.

[This message has been edited by Marko Stojovic (edited 07-23-2001).]

[This message has been edited by Marko Stojovic (edited 07-23-2001).]
 
Hi Marko,

the code you've used is looping thru all the items in the list box, not just the selected ones. The itemsselected will give you the number as you have correctly, but ItemData refers to all the items in the box, not just the selected ones, which suggests that the first item of your list box contains a null value in its first field(?). I always use something like the below as vItem then keeps the index of the current item as a part of the entire box rather than it's selection index.

Code:
Dim vItem As Variant

For Each vItem In Me.List0.ItemsSelected
    If Not IsNull(Me.List0.ItemData(vItem)) Then
        Debug.Print Me.List0.ItemData(vItem)
    End If
Next

hope that made some kind of sense...

Drew
 

Users who are viewing this thread

Back
Top Bottom