add item to combobox vb6

Hi,
 I want to add items to my combobox, I did it, but the problem is the index of each item, I want to give the index value.
how do i do it.

i need it becuase when the user select employee name i want to update my database for this employee by it's Badge.

thnx
madmareAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EricDelcroixCommented:
Try this : paste the code into the Declarations section of a form that contains a ListBox and a Label. Set the Sorted property for the ListBox to True.

Option Explicit
Private Sub Form_Load()
   
    Label1.Caption = ""
   
    With List1
        ' Fill List1 with names and fill ItemData array with
        ' a number (let's badge number)
        .AddItem "Judy Phelps"
        .Refresh
        .ItemData(.NewIndex) = 42310
        .AddItem "Chien Lieu"
        .ItemData(.NewIndex) = 52855
        .AddItem "Mauro Sorrento"
        .ItemData(.NewIndex) = 64932
        .AddItem "Cynthia Bennet"
        .ItemData(.NewIndex) = 39227

   End With
End Sub

Private Sub List1_Click()
   Dim msg As String
   ' Display the employee badge and the employee name.
   With List1
        msg = .ItemData(.ListIndex) & " "
        msg = msg & .List(.ListIndex)
        Label1.Caption = msg
   End With
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EricDelcroixCommented:
Oh yes, it also works fine with a ComboBox : just change the Listbox with a ComboBox :

Option Explicit
Private Sub Form_Load()
   
    Label1.Caption = ""
   
    With Combo1
        ' Fill combo1 with names and fill ItemData array with
        ' a number (let's badge number)
        .AddItem "Judy Phelps"
        .Refresh
        .ItemData(.NewIndex) = 42310
        .AddItem "Chien Lieu"
        .ItemData(.NewIndex) = 52855
        .AddItem "Mauro Sorrento"
        .ItemData(.NewIndex) = 64932
        .AddItem "Cynthia Bennet"
        .ItemData(.NewIndex) = 39227
        .ListIndex = 0
   End With
End Sub

Private Sub combo1_Click()
   Dim msg As String
   ' Display the employee badge and the employee name.
   With Combo1
        msg = .ItemData(.ListIndex) & " "
        msg = msg & .List(.ListIndex)
        Label1.Caption = msg
   End With
End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.