Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView - Date Column -Format & Error Message? 1

Status
Not open for further replies.

Mahey

Programmer
Dec 24, 2008
52
SA
Hi,

With My Datagridview - I have a column for date. and it's defaut format is mm/dd/yyyy. But Iam looking to read the date by "dd/mm/yyyy" format. Also if the user feed wrong date format then it has to display my Error message. "INVALID DATE"

Any Ideas Will be appreciated.

THANKS
 
If you are using a BindingSource:

Right-click on the grid and select "Edit Columns..." from the popup. In the Edit Columns dialog select the column you want to format, then select the DefaultCellStyle property from the list on the right. Click the little ellipsis button to show the CellStyle Builder. In the format field, enter dd/MM/yyyy. Click OK to close the CellStyle Builder, the OK again to close the Edit Columns dialog. The cell should now be showing the correct format. One advantage of this is that if someone enters 12/30/2008 (Dec. 30, 2008), the formatting will automatically change it to 30/12/2008. To capture invalid dates, handle the DateError event.

If you are assigning the data source in code, you can do all of the above but you have to add an unbound column and format that.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top