简体   繁体   English

删除当前选定的绑定组合框项目,然后什么都不选?

[英]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. 在删除当前选定的绑定项目之后,如何使组合框什么也不做选择(即SelectedIndex = -1 )。 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. 我也喜欢@Cody Gray在评论中提出的建议。 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. 但是,我想到了这一点,您可能能够做到这一点的另一种方法是,附加一个事件,当您从ComboBox中删除一个项目时会触发该事件。 Set the SelectedIndex = -1 in that event handler. 在该事件处理程序中设置SelectedIndex = -1 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: 在Cody Gray发布的已知错误链接中,解决方法是:

SelectedIndex = 0
SelectedIndex = -1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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