Reputation: 3459
I have a Windows Forms project in Visual Studio 2010 and I was wondering how I would set a default selected value of a dropdown menu.
For example, when I run the project currently the dropdown menu is blank until I click on it and select a value. I want to modify the dropdown menu so that it has a value by default that the user can then change. How can I accomplish this both in the designer view and at runtime through C#?
Upvotes: 1
Views: 9104
Reputation: 30123
Set property SelectedIndex.
Run-time:
comboBox1.SelectedIndex = 0; //Selects the first option
If you want to select option that contains specific text.
int index = comboBox1.FindString("burger"); //get index
comboBox1.SelectedIndex = index;
Design-time:
Select the control, go to property window and look for SelectedIndex property, set the desired index.
Upvotes: 2