Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winforms Combobox SelectedValue is 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.

like image 213
Taryn Avatar asked Oct 05 '10 21:10

Taryn


2 Answers

Maybe, you just need to use the SelectedItem, instead!

like image 112
Steven Avatar answered Sep 30 '22 11:09

Steven


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.

like image 32
Jeff Ogata Avatar answered Sep 30 '22 12:09

Jeff Ogata