I want to store the cell value of the DataGridView
control, but this variable is always storing null values, whether or not the cell contains a value.
var cellValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
If I do the following:
string cellValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() ;
it produces the error:
NullRefrenceException was unhandled .
I used it in various events like CellEndEdit
, CellValidating
, CellLeave
, but the result is the same. What should I do to save the correct value in hte cell including null also (ie. if any cell is empty).