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

Check for valid date when editing in DataGridView

$
0
0

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



Viewing all articles
Browse latest Browse all 2535

Trending Articles



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