简体   繁体   中英

Manually change the selected item in a combo box

I am trying to manually change the selected item in a combo box so that it will physically change the value on the interface. I have tried changing the index value and display value on the drop down list, but this does not change the value on the interface. Has anyone ever done this?

Use case: A user adds a new value to the database. The observable collection that feedsd the combo box is updated in memory with the new value to choose from. But, you want to save the user a click and just make the new value they added as the selected item in the combo box, rather than forcing them to add the new item, and then go over to the combo box to select it.

If you really want to do this...

You could try:

yourComboBox.SelectedItem = // the new Object that you want to set the comboBox to;

If the object is found, it will also automatically update the SelectedIndex .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM