Selecting default item from Combobox C#

前端 未结 7 855
灰色年华
灰色年华 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:43

    private void comboBox_Loaded(object sender, RoutedEventArgs e)
    {
     Combobox.selectedIndex= your index;
    }
    

    OR if you want to display some value after comparing into combobox

     foreach (var item in comboBox.Items)
                {
                    if (item.ToString().ToLower().Equals("your item in lower"))
                    {
                        comboBox.SelectedValue = item;
                    }
                }
    

    I hope it will help, it works for me.

提交回复
热议问题