DataGridViewComboBoxColumn, Guid and DBNull problem

G

Guest

Hi,

I have a datagridview bound to a datatable with two columns: "x" and "y".
"x" is of type Guid, it can accept DBNull and is a foreign key to another
table.

In my datagridview I would like to let the user edit the value of "x"
through a combobox.

I have defined the column to be DataGridViewComboBoxColumn and set the
propetyname to "x".

Before binding the grid, I bind the DataGridViewComboBoxColumn combo to a
datatable which inclueds all the allowed values from the realtion, plus an
additional row with DBNull.Value as its value and empty string as the
displayed value and have defined the columns ValueMember and DisplayMember
accordingly.

This is supposed to allow the user to select either DBNull or a valid value
for column "x".

Whenever the user selects the empty combo value (which has the value of
DBNull) I get an exectpion that I cannot set the value to null, and must use
DBNull.

I have tried to change the cellstyle.DataSourceNullValue to DBNull (which is
supposed to be the default) and handle the parsing event as set empty string
to DBNull.value but none helped.

By the way, I have the exacly the same scenario with a column of type string
that works great.

What am I doing wrong? Is this a bug in datagridview? Maybe I have an old
version?

Thanks,

Dani
 

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