Reputation: 247690
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.
Upvotes: 7
Views: 33324
Reputation: 1994
ComboBox has to have DataSource. Link data though ComboBox1.DataSource
Upvotes: 12
Reputation: 57783
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.
Upvotes: 13