Adding a GridView to the Form Designer and using a drop-down list in one of the columns bound from a database source/table causes the following .NET error when loading the form at runtime:
[FIELD] has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
This is because the drop-down list default is a String.Empty
value, and so it cannot find a valid item with an empty value in the drop-down list, since it is bound to a database table that doesn’t contain a record of which value column has a String.Empty
value.
The solution is to define a static default item in the drop-down list. To do this:
-
In the Form Designer, click the pencil icon next to the drop-down list to open the Settings window.
-
On the Items tab, add a static default item with the
value=""
(without blank spaces) andText="Select..."
-
On the Databind tab, check the Append data bound items option.