Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MM .NET Tip 'O The Day
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
MM .NET Tip 'O The Day
Miscellaneous
Thread ID:
00814617
Message ID:
00814617
Views:
43
This isn't specifically an MM .NET tip, but it's a question I've had to answer often.

How do you programmatically select an item in a ComboBox or ListBox? You can do this by setting its SelectedIndex property.

For example, in C#:
this.lstEmployees.SelectedIndex = 1;
And in VB .NET:
Me.lstEmployees.SelectedIndex = 1
If you don't know the index number of the item you want to select, but you know it's text display value, you can use the FindString or FindExactString method to find the item index.

For example, in C#:
this.lstEmployees.SelectedIndex = this.lstEmployees.FindExactString(SelectedText);
And in VB .NET:
Me.lstEmployees.SelectedIndex = Me.lstEmployees.FindExactString(SelectedText)
Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Reply
Map
View

Click here to load this message in the networking platform