Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box Itemdata Issue 3

Status
Not open for further replies.

Sech

Programmer
Jul 5, 2002
137
GB
I'm creating an application where I need to run through a list box of values and where the value matches a pre-chosen variable it needs to be automatically highlighted (will usually be multiple highlights). I thought I could obtain the values shown in the list by using the itemdata command e.g. lstCustomers.Itemdata(0) should return the first value in the list? However despite there being a value in the list, it returns a 0. What am I doing wrong? Do I need to use a different command? I have used this command numerous times in Access before without fail, but never tried it in VB6 before (Note: The list box has been pre-filled from a database table and then the database connection has been closed)
 
The ItemData value returned is similar to the index of the item, telling you it's position in the ItemData array. To do what you require I'd use
Code:
List1.List(0)
Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
You will need to set the MultiSelect property of the ListBox to 1.

For i = 0 To List1.ListCount - 1
If List1.List(i) = my pre-chosen variable Then
List1.Selected(i) = True
End If
Next i

This will highlight any matches. If you want to read the value of an item then myvalue = List1.List(i)

[gray]Experience is something you don't get until just after you need it.[/gray]
 
> using the itemdata command

Just to clarify, it's not a "command" or method. It is a Property. It's like a Tag property, except it only accepts a Long value instead of a string.
This property can basically be set to a Long value at any time, which can be used for whatever purpose you want.
 
Thanks very much to you all
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top