Groups | Blog | Home
all groups > dotnet windows forms databinding > november 2004 >

dotnet windows forms databinding : DropDown list, bound to a datatable with a null value throws an ArgumentOutOfRangeException



John Murray
11/21/2004 11:14:44 AM
In windows forms, I have a combobox (dropdownlist) with selections
populated from a datatable (using ValueMember = key, DisplayMember =
description and DataSource.) The datatable comes from a SQL Query and I
am manually putting a value in position 0 of the returned datatable with
DBNull for the key and DBNull for the description. This displays the
values correctly with an empty selection at the top -- which is what I want.

Now, when I bind this new a recordset, where the SelectedValue of the
combobox is bound to a column with a null value, I get an
ArgumentOutOfRange exception related to the null value in that column (I
know this because when I populate this column with a value (1 for
example) the binding works fine.

leading to the question -- how can I bind to a combobox such that no
selection leads to a null value being inserted in the bound datatable?
Mohamed Osman
1/26/2005 10:41:02 PM
I am experiencing the same problem currently. The solution was to create a
dataset and merge the table into the dataset.
It works fine binding to the datatable as part of the dataset. Merging it
is important.

[quoted text, click to view]
AddThis Social Bookmark Button