System.ArgumentException: Cannot set column "ColumnName" to be null. Please use DBNull instead.

L

lgalumbres

Hello,

I have a DataGridView control with a DataGridViewComboBoxColumn that
allows users to choose selections from a list. The DataGridView is
bound to a DataTable object and the DataGridViewComboBoxColumn is bound
to a DataTable as well and the link between the two tables is by a
field called "ClassID" which is of integer data type. Both DataTables
are populated from a server call.

With the DataGridViewComboBoxColumn a user is allowed to choose an
empty selection which has a "ClassID" = -1.

The problem is that everytime the empty selection is chosen, an
exception is thrown:

System.ArgumentException: Cannot set column "ClassID" to be null.
Please use DBNull instead.

This only seems to happen when the value member is of Integer type.
Ive tried replacing the "ClassID = -1" to "ClassID =DBNull.Value" and
it doesnt work. Technically, the ClassID = -1 should work but no go.
Ive even gone further by explicitly creating each column and each row
for the DataTable and still doesnt work.

Has anyone ran into this problem before? If so, how did you workaround
the problem?

Thanks in advance,
Lem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top