Programmatically select an item in a ListBox control

Posted on 2004-11-19
Medium Priority
Last Modified: 2008-03-17
At runtime, how do I programmatically select an item in a ListBox control.

The result would be as if I had clicked on it with the mouse.....meaning the underlying event would fire.
Question by:Tom Knowlton
1 Comment
LVL 51

Accepted Solution

Steve Bink earned 2000 total points
ID: 12628637
You would use the .Selected property of the listbox.  For example, to select the first item, use this line of code:

Me.MyListboxName.Selected(0) = True

Selecting an item programmatically will not fire the OnClick event for the listbox.  Only a mouse click will do that.  You CAN call the event manually, however.  For example, to select the fourth item in the listbox, then fire the event:

Me.MyListboxName.Selected(3) = True

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

850 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