Reputation: 31
Hello does anyone here know how to set a default value for A combo box? By the way I'm using microsoft visual studio 2010. I can't find any option in the properties tab. :((
Do you know any site which offers comprehensive tutorial about visual studio 2010? This software is really killing me...
Upvotes: 1
Views: 4999
Reputation: 588
ComboBox1.FormattingEnabled = True
ComboBox1.Items.AddRange(New Object() {"Value A", "Value B"})
ComboBox1.SelectedIndex = 0
This will show Value A as the default selected value for a combobox
Any value above 0 will work, the default value for SelectedIndex is -1 which means that no value is shown, so you have to use anything above 0, depending on what value you need to show.
Upvotes: 0
Reputation: 11687
All may work.
comboBox1.SelectedIndex = 0; // what ever index you want
comboBox1.Text = "String"; // what ever index you want
comboBox1.SelectedValue = obj; // an objet value
Hope it helps.
Upvotes: 1
Reputation:
You may want to take a look at the SelectedIndex property. To set the combobox to the first item in your collection you would write.
Form1_load(object sender, EventArgs e)
{
ComboBox1.SelectedIndex = 0;
}
Upvotes: 0
Reputation: 292405
There isn't a "default value" property, but you can set the selected value in the Load
event:
private void Form_Load(object sender, EventArgs e)
{
comboBox1.SelectedValue = ...
}
Upvotes: 0