1

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...

2
  • Are you using Windows Forms, WPF, or what? Commented Sep 4, 2011 at 2:46
  • 4
    @John: I've noticed that when someone doesn't know which UI framework they're using, or just refers to it as "C#", it's usually WinForms ;) Commented Sep 4, 2011 at 2:49

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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 = ...
}

Comments

0

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;
}

3 Comments

Can I just have a follow up question here? or should I post a new topic??
@warook you should mark THE answer as answer and then post another separate question.
@warook If you agree with the answer I posted, it would be the appropriate thing to do to mark my answer as correct. Also, feel free to ask another question here.
0
    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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.