Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataGridView Cell value (DBNull instead of NULL)

$
0
0

hi,

 

i have this problem :

 

i have a DataGridViewComboboxColumn in a DataGridView. 

this DGV is bound to a DataTable.

 

when i edit my column (ComboBoxColumn) and select any items from the combobox, every this is ok

but when i delete the text in the text zone of the combobox i 'll get an error.

 

that's fine, the problem is that, when i delete the text content, the SelectedValue of that combo is NULL

and when it's time to set that value back to the cell (or the DataTable field, i don't know exactelly witch one)

 

i get this error '' Cannot set column <culumn name>  to be null. Please use DBNull instead. "     

 

this error message is self explanatory. but i couldn't find a way to get rid of it.

 

i tried this

 

Code Snippet

// this is the function attached to the CellValidating event

//*************************************************************************************

privatevoid dgView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)

{

   if (e.ColumnIndex == dgView.Columns["myComboColumn"].Index)

   {

     if (e.FormattedValue == null || e.FormattedValue.Equals(""))

     {

        dgView.CurrentCell.Value =

DBNull.Value;

     }

   }

}

 

 

but it does not work.

 

so, any ideas, links, ...  are welcome.

 

Thanks.   


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>