I have a datagridview(dgv) control which is bound to a typed dataset.
There is a hidden column called "ItemId", it is a not null column in database, this is used when update the data in dgv.
Now, when the application is start and I create a new application, the dgv is empty and user need to type in data in the dgv.
However, when I finish editing a row, and try to exit out from the row, I got an Exception "Column ItemId does not allow null".
What should I do to allow the dgv to ignore the null ItemId
Thank you in advance.

Datagridview Exception: column does not allow null
satjay
Hi Alan,
Thanks for the reply.
I need the ID when user update the DGV, I need this to tell the database which data to update.
I take your suggestion which set the DGV to Virtual Mode and set the CellValueNeeded like this, and it works!
private void datagridview1_CellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e){
if (e.ColumnIndex == 2) //Description{
this.datagridview1.Rows[e.RowIndex].Cells[0].Value = e.RowIndex; //put a dummy value in Column 0(ID)}
}
KzooBoy
Matt Milner - Pluralsight
Hi Terrence,
I don't think it's possible to by-pass it unless you've lossen the constriant.
For your case, I think you should set the identity column incremental seed and value to -1. So that it'll get the value when inserted into the database. Moreover, I think you can use the VirtualMode of DGV and the CellValueNeeded event to fill up the item id.