By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,929 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,929 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Oct 30 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.