Compairing datetime in datagridview wrong

Sep 10 2009 4:13 AM

Hi

What wrong with my code

I'm using datagridview with C#. There are two columns in my grid (day1 and day2 bounddata). I want to validate day 2 not smaller than day 1. The problem is that I can't the the latest value of day 2 column. Day 2 always return the old value of it. Help me pls.

Thank you so much.

 

 

        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)

        {

            if (e.ColumnIndex == 2)

            {

                DateTime day1 = (DateTime) dataGridView1.Rows[e.RowIndex].Cells[2].Value;

                DateTime day2 = (DateTime) dataGridView1.Rows[e.RowIndex].Cells[3].Value;

                if (day2 < day1)

                {

                    MessageBox.Show("Day 1 not smaller than day 2");

                }

           }

 

        }

 


Answers (2)