VS2010/C#: How do you set the default value of a ComboBox in the IDE?

前端 未结 3 789
别那么骄傲
别那么骄傲 2021-02-20 07:49

I\'m writing a Windows Forms app in C#, using Visual Studio 2010.

It has a combo box. I\'ve set the DropDownStyle to \"DropDownList\", and added a few lines to \"Items\

3条回答
  •  青春惊慌失措
    2021-02-20 08:19

    I'm not sure if this is what your asking for but if you want a specific item to be set as default I.E you load the form and there is already a value selected for you.

    Simply put this into your public Form1() method.

    comboBox1.SelectedItem = "Test1"; 
    //comboBox1 change to the name of 
    //your combobox
    //Test1 change to the item in your list of items that you want 
    //defaulted.
    

    I think that is by far the best way to do it.

提交回复
热议问题