如何在DataGridView中验证正确的日期

时间:2017-11-04 07:28:09

标签: c# winforms datagridview

我有两列从日期和到目的地,我想阻止用户选择新行,直到用户输入正确的日期,目前我正在使用的方法只是允许用户选择新的日期选择是错误的。< / p>

private void metroGrid1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
            {
                DataGridView view = sender as DataGridView;
                DateTime fromDate = Convert.ToDateTime(metroGrid1.Rows[e.RowIndex].Cells["fromDate"].Value);
                DateTime toDate = Convert.ToDateTime(metroGrid1.Rows[e.RowIndex].Cells["toDate"].Value);

                if (fromDate > toDate)
                {
                   MessageBox.Show("From Date Must be less than To Date");
                }

            }

0 个答案:

没有答案