How do I programmatically select items in a list box?
There are a few ways you can select items in a list box, depending on how it was originally bound to data.
Regardless of how a list box has been data bound, it's easy to set the SelectedIndex property of a list box to specify the item number you want to select.
In C#:
MyListBox.SelectedIndex = 0;In VB .NET:
MyListBox.SelectedIndex = 0However, if you're data driving a list box, you often don't know the index number of the item you want to select. If you have bound a list box to a string array, you can programmatically select an item in the list box by setting its SelectedItem property:
In C#:
MyListBox.SelectedItem = "MyText";In VB .NET:
MyListBox.SelectedItem = "MyText"If the listbox is bound to a data table or data view, the previous code won't work. Instead, you can programmatically select an item by setting the list box's Text property:
In C#:
MyListBox.Text = "MyText";In VB .NET:
MyListBox.Text = "MyText"
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/10/08
Comment or report problem with topic
