组合框的WinForms是的SelectedValue空 [英] Winforms Combobox SelectedValue is Null

查看:111
本文介绍了组合框的WinForms是的SelectedValue空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据输入形式,对了好组合框。每个组合框有它自己的绑定源,它是正确的填充时我启动的形式。但是,如果我编辑表单上的记录,并尝试传递到数据库更新的SelectedValue从ComboBox我得到的价值,我向它传递NULL错误。

I have a data entry form that had several comboboxes on it. Each of the combo boxes has its own binding source and it is populating correctly when I launch the form. However, if I edit the record on the form and try to pass to the database the updated selectedvalue from the combobox I get an error that the value I am passing it NULL.

这问题似乎每个其他时间我运行织补的事情发生,我想不通为什么它不能正常工作。基本上我试图插入一个新的记录到表中,但出于某种原因未能拉我选择的值。我的代码中插入的数据如下:

This issue seems to happen every other time I run the darn thing and I can't figure out why it is not working properly. Basically I am trying to insert a new record into a table but for some reason it is failing to pull my selected value. My code to insert the data is below:

Data.Manager.AddEmployee
 (
   InactiveEmployeeSelected.GUID,
   Convert.ToByte(RoleComboBox.SelectedValue),
   NotesTextBox.Text.Trim(),
   ScheduleTextBox.Text.Trim(),
   ExtensionTextBox.Text.Trim(),
   CodeTextBox.Text.Trim(),
   Convert.ToBoolean(EBApprovedCheckbox.CheckState),
   Convert.ToByte(ApprovalLevelComboBox.SelectedValue),        //pulling null
   Convert.ToBoolean(AssignComtracksCheckbox.CheckState),
   Security.Manager.CurrentUser.GUID,
   DateTime.Today,
   Convert.ToBoolean(IsActiveCheckbox.CheckState)
);



任何帮助将不胜感激。

Any help would be greatly appreciated.

推荐答案

您使用的是 DropDownStyle 下拉并键入到组合框?如果是这样,这将导致的SelectedValue 为空,我假设,因为输入的值不再是在组合框

Are you using a DropDownStyle of DropDown and typing into the ComboBox? If so, that will cause SelectedValue to be null, I'm assuming because the value entered is no longer one of the items in the ComboBox.

如果是这种情况,将 DropDownStyle DropDownList的,假设用户已经挑现有的值。

If this is the case, set the DropDownStyle to DropDownList, assuming the user has to pick an existing value.

这篇关于组合框的WinForms是的SelectedValue空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆