Link to home
Start Free TrialLog in
Avatar of Lee W, MVP
Lee W, MVPFlag for United States of America

asked on

VB6 - Combo Control/Drop Down Question

In HTML, if I want to display one thing, but get a different value I would do something like this:

<select name="combo">
<option value=1>John Doe</option>
<option value=2>Jane Smith</option>
<option value=3>Joe Blow</option>
</select>

How can I do the same thing (combo which assigns a value of 1 if John Doe is selected, etc) in VB6, figure using a combo control or maybe a list box?
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bingie
bingie

Sure can, but it can only be integer data.

You can use the Combo1.ItemData(index as integer) property, when index is the index of the item

Add a combo box and paste the following (just select and item) to see how to do it:

Private Sub Combo1_Click()
 MsgBox Combo1.ItemData(Combo1.ListIndex)
End Sub

Private Sub Form_Load()
 Combo1.AddItem "first"
 Combo1.ItemData(0) = 1
 Combo1.AddItem "second"
 Combo1.ItemData(1) = 2
 Combo1.AddItem "third"
 Combo1.ItemData(2) = 3
End Sub
Avatar of Lee W, MVP

ASKER

I thought so... but the documentation I looked at didn't seem clear on this.  Thanks, I'll test things and let you both know.
hi
u can also use NewIndex Property to get newly added entry
'===============================
Private Sub Form_Load()
Dim i
    For i = 1 To 10
        Combo1.AddItem "Item " & i
        Combo1.ItemData(Combo1.NewIndex) = i
    Next i
End Sub
'===============================

;-)
Shiju
Ok, working on it again now (if I don't finish today, won't get back to it until Monday).  That said, how do I retrieve BOTH the index and the text data?
Thanks folks - have to select Erick37 as the answer - The link he provided was REALLY helpful and he did post first.