error in datagridview

  • Thread starter Thread starter Ravi Kumar12233
  • Start date Start date
R

Ravi Kumar12233

Guest
Dear all ,

In my data-grid view for one column called "Next calibration" i am using below code to highlight the cell if the date is over( compared to today) .

private void dataGridViewforentryform_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
try
{
var cellvalue = dataGridViewforentryform.Rows[e.RowIndex].Cells["nextCalibrationOnDataGridViewTextBoxColumn"].Value;
if (Convert.ToDateTime(cellvalue) < DateTime.Now)
dataGridViewforentryform.Rows[e.RowIndex].Cells["nextCalibrationOnDataGridViewTextBoxColumn"].Style.ForeColor = Color.Red;
dataGridViewforentryform.Rows[e.RowIndex].Cells["nextCalibrationOnDataGridViewTextBoxColumn"].Style.SelectionForeColor = Color.Red;
}
catch (Exception)
{

// throw;
}

}


How ever if i select any other row in my data-grid view & try to close the form this below error is coming , please guide me how to solve this.



1613278.png

Continue reading...
 
Back
Top