简体   繁体   中英

Delete currently selected bound combobox item and then have it select nothing?

How can I make a combobox select nothing (ie. SelectedIndex = -1 ) after deleting the bound item that was currently selected. I don't like how the next item gets selected after the currently selected item gets deleted. This could lead to some problems with the wrong value being selected. Would be ideal if there was a way to add this behaviour directly to an inherited combobox.

I also like the suggestion made by @Cody Gray in the comments. However, I thought about this and another way you might be able to do this is by attaching an Event which fires when you remove an item from the ComboBox. Set the SelectedIndex = -1 in that event handler. Now, I am not sure if there is such a readily available event, so it might be worthwhile to look into it.

In the known bug link posted by Cody Gray, the workaround is to do:

SelectedIndex = 0
SelectedIndex = -1

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