Check for valid date when editing in DataGridView

  • Thread starter Thread starter john pp nn
  • Start date Start date
J

john pp nn

Guest
Hi folks,


I have a datagridVoew control. One of the colums is set up like this...


grdPurchaseLedger.Columns[colNum].Name = "docDate";
grdPurchaseLedger.Columns[colNum].HeaderText = "Date";

grdPurchaseLedger.Columns[colNum].DataPropertyName = "docDate";
grdPurchaseLedger.Columns[colNum].Width = 120;

grdPurchaseLedger.Columns[colNum].DefaultCellStyle.Format = "d";

grdPurchaseLedger.Columns[colNum].DefaultCellStyle.ForeColor = Color.Blue;
grdPurchaseLedger.Columns[colNum].ReadOnly = false;


If the user tried to change the date to an invalid date eg 12345 then I get the following error message

System.FormatException: 'String was not recognized as a valid DateTime.....

Is there any way I can check the date value myself to prevent the default error message from appearing ?

I have tried using the CellEndEdit event but the default message still appears.

Thanks,


John




jppnn

Continue reading...
 
Back
Top