简体   繁体   English

消除组合框中的空条目

[英]Eliminate null entry in combobox

Is there any property to remove the first (and empty) item in a combobox with style DropDownList ? 是否有任何属性可以删除带有样式DropDownList的组合框中的第一个(和空)项? In other words, I would like to choose the default selected item for a combobox. 换句话说,我想为组合框选择默认选定项。

I know i can validate the selected item with code, but i want to avoid showing message boxes to the user. 我知道我可以使用代码验证所选项目,但我想避免向用户显示消息框。

comboBox.SelectedIndex属性设置为0以将选择设置为组合框中的第一个项目。

You should set the Text or SelectedIndex or SelectedValue property. 您应该设置TextSelectedIndexSelectedValue属性。 In this way the combobox updates the text that's is showing and removes the first empty item (that actually is not a real item). 通过这种方式,组合框更新正在显示的文本并删除第一个空项(实际上不是真项)。

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

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