selecting an item in a list or combobox

Posted on 2005-04-30
Last Modified: 2010-05-02
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!
Question by:efinger
    LVL 14

    Expert Comment

    by:Shiju Sasidharan

    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    where index is the index of the item u want to make as selected

    index =3
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    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
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    otherwise go through each entry and check ur matching string is reached ...
    LVL 14

    Accepted Solution

    for better solution
    use winSendMessageS function specified in the above link
    LVL 13

    Expert Comment


    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now