Selecting default item from Combobox C#

前端 未结 7 1016
灰色年华
灰色年华 2021-01-03 18:25

I have few items on my ComboBox items collection, and i\'d like to select one item from this list and set it as default item - when app starts - this item is al

7条回答
  •  感动是毒
    2021-01-03 18:52

    You can set using SelectedIndex

    comboBox1.SelectedIndex= 1;
    

    OR

    SelectedItem

    comboBox1.SelectedItem = "your value"; // 
    

    The latter won't throw an exception if the value is not available in the combobox

    EDIT

    If the value to be selected is not specific then you would be better off with this

    comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
    

提交回复
热议问题