WPF combobox value and display text

后端 未结 4 1113
無奈伤痛
無奈伤痛 2021-02-12 02:30

I\'m used to doing things like

State.Items.Add(new ListItem { Text = \"SomeState\", Value = NumericIDofState });

Where State is a Listbox in A

4条回答
  •  半阙折子戏
    2021-02-12 03:24

    If you skip the Value, then I think it's quite simple to add a new item into a ComboBox during runtime.

    comboBox1.Items.Add("SomeText");
    
    comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
    

    The SelectedIndex property is set to Items.Count-1 so that the newly added item appears in the ComboBox as the selected item.

提交回复
热议问题