Issues setting combobox DropDownStyle = DropDownList

lsdev

Well-known member
Joined
Jan 20, 2008
Messages
61
Programming Experience
1-3
Basically I have gone through my working application and changed my combobox's so they are not longer editable (from a dropdown to dropdown list), but on testing have found some very strange results.
Basically I have tested it and found that no matter what selection the user selects my update fails!!
This is due to the combobox value being null?? I have changed it back (dropdown) and it's fine, so is there another option you need to check to get this funtionality to work?
 
have you set the .selectedValue property in your data binding?

A combobox needs 3 settings if it's to be used as a "lookup" for a field in a table

(a) DisplayMember (the name)
(b) ValueMember (the ID of that row)
(c) DataBindings.SelectedValue (the field in your table that has the lookup, this basically sets the value that is set to the ValueMember)


EDIT: although not sure why this works when you change back to DropDown...DropDownList is exactly the same, but "read only"
 
Basically I have gone through my working application and changed my combobox's so they are not longer editable (from a dropdown to dropdown list), but on testing have found some very strange results.
Basically I have tested it and found that no matter what selection the user selects my update fails!!
This is due to the combobox value being null?? I have changed it back (dropdown) and it's fine, so is there another option you need to check to get this funtionality to work?

Previously you were binding the .Text value to the table column to be updated. Now you must bind the .SelectedValue

You must also ensure that the .ValueMember of the combo is set to a string name of a column present in the combo .DataSource underlying datasource
 
EDIT: although not sure why this works when you change back to DropDown...DropDownList is exactly the same, but "read only"

Combo in DD mode by default, bind the .Text property because the user can edit the text. Binding the .SelectedValue would mean that no matter what the user types, the column sets to the selected value from the list

If you want freeform editing with list suggestions, use DD and bind .Text (and .Displaymember must be set)
If you want lookup and set for fixed list only, use DDL and .SelectedValue (and .ValueMember msut be set)
 

Latest posts

Back
Top