Compare today's date to a column and highlight the cell

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

Ravi Kumar12233

Guest
In my winform app , there is a column called "Next_Calibration_On"(in the format "dd-MM-yyyy") with which i have to compare today date if it is less than it then i want highlight the cell in the datagrid view in red . Fr this i have the below code :

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DateTime currentToday = (DateTime)this.dataGridView1.Rows[e.RowIndex].Cells["Next_Calibration_On"].Value;

if (currentToday <= DateTime.Now.Date)
{
e.CellStyle.ForeColor = Color.Red; //Font Color
e.CellStyle.SelectionForeColor = Color.Red; //Selection Font color
}

However this is showing the error message as below:

System.ArgumentException: 'Column named Next_Calibration_On cannot be found.Parameter name: columnName'
But i do have column in my table ..how to solve this?1611900.png

Continue reading...
 
Back
Top