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.
Maybe, you just need to use the SelectedItem
, instead!
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
.
If this is the case, set the DropDownStyle
to DropDownList
, assuming the user has to pick an existing value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With