
How to duplicate Access' listbox in VB6
Use the ItemData property of the ListBox. Each item in the list has an
associated ItemData (data type = Long). Note that List1.NewIndex always
points to the last item added to List1.
List1.AddItem "Big Hammer"
List1.ItemData(List1.NewIndex) = 1234
List1.AddItem "Little Hammer"
List1.ItemData(List1.NewIndex) = 2345
List1.AddItem "Mini-Hammer"
List1.ItemData(List1.NewIndex) = 3456
To find the ID for the selected item...
Dim lItemID As Long
lItemID = List1.ItemData(List1.ListIndex)
HTH,
Rocky
Quote:
> In Access, I can load a recordset into a listbox.
> Maybe this recordset has product no. and product description
> User doesn't care about product no., just wants to see description, so I
can
> set column 1 to 0 width and leave column 2, the description for user to
> select.
> My code takes the column 1 value, the product no. as it's selection.
> Example:
> 1234 Big Hammer
> 2345 Little Hammer
> 3456 Mini-hammer
> Customer clicks Mini-hammer, but the value 3456 is passed in my code
> How do I duplicate this in VB6?
> Do I have to buy a special listbox control?
> Thank you!
> Tony