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

error in datagridview

$
0
0

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.




Viewing all articles
Browse latest Browse all 2535

Trending Articles



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