[英]save default value in combobox when nothing is selected c#
In my winform data entry application, I have a combo box set to "Dropdown List" so the user couldn't add any values other than items present in my combo box.在我的 winform 数据输入应用程序中,我有一个组合框设置为“下拉列表”,因此用户无法添加除组合框中存在的项目以外的任何值。 but while saving if the user doesn't select any item in the combobox I need to save the form with default value("Mg"), but whenever I try to save it shows the field can't be null as it doesn't accept null values:但是,如果用户不保存 select combobox 中的任何项目,我需要使用默认值(“Mg”)保存表单,但是每当我尝试保存它时,显示该字段不能是 Z37A6259CC0C1DAFFF09ZA7D86接受 null 值:
what I've tried during (save button click event) 1:我在(保存按钮单击事件)1中尝试过的内容:
string unitcb = unitComboBox.Text;
finishUOMComboBox.Text = uomtxt;
try2:尝试2:
finishUOMComboBox.SelectedText = "Mg";
try3:尝试3:
finishUOMComboBox.ValueMember = "Mg";
try4:尝试4:
finishUOMComboBox.Text = "Mg";
try5:尝试5:
finishUOMComboBox.selctedindex = 0;
please help how to save "mg" in the combbox when nothing is selected or it is null while saving.请帮助如何在未选择任何内容时在组合框中保存“mg”,或者在保存时它是 null。
Try this way to get ComboBox selected item:试试这种方式获取 ComboBox 选中项:
finishUOMComboBox.selectedItem.ToString();
This code returns your selection's value此代码返回您选择的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.