selecting an item in a list or combobox

I typically maintain list and combo boxes with the record id in the 0th column.

I know in a list for instance, it's easy to select the value you want if you know it's index; but what if you only know the value of of the record id (ie, employeeID)

What's the best way to select it in the list (and make sure it scrolles into view?

How about for a combo box.

Any tips and advice much appreciated!
Who is Participating?
Shiju SasidharanAssoc Project ManagerCommented:
for better solution
use winSendMessageS function specified in the above link
Shiju SasidharanAssoc Project ManagerCommented:

Shiju SasidharanAssoc Project ManagerCommented:
where index is the index of the item u want to make as selected

index =3
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Shiju SasidharanAssoc Project ManagerCommented:
oops combo ?
try to set the combo text

   Combo1.Text = your_Employee_Id

if its  style is - 2 then it may generate error if the id u try to set is not in the combo
Shiju SasidharanAssoc Project ManagerCommented:
otherwise go through each entry and check ur matching string is reached ...

Add a listBox to a vb project (List1) and try this code

' Add 100 item to test on
For i = 1 To 100
    List1.AddItem "Item " & CStr(i)
    ' we use item data that holds custom numeric data (ID in our case)
    ' because listindex could be different than the ID especially if
    ' the IDs have a number missing in the middle
    List1.ItemData(List1.NewIndex) = i

For i = 1 To List1.ListCount
    If List1.ItemData(i) = 50 Then
        ' if we find the item we select it and exit the loop
        List1.ListIndex = i
        Exit For
    End If
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.