Solved

URGENT! VB.NET -- Need to format DataGridViewCell Value as Date ("MM/DD/YYYY")

Posted on 2013-01-19
4
2,427 Views
Last Modified: 2013-01-29
Hi everyone,

When a user types a date value into a DataGridViewCell, I want to format it as "MM/DD/YYYY".

The underlying database table does not have any date columns hence the reason for forcing the input as a date.

Where should I start?

Thanks!
0
Comment
Question by:eq2006
  • 2
4 Comments
 
LVL 9

Expert Comment

by:sognoct
ID: 38797267
you can set the cell format to datetimepicker

snippet here :
http://msdn.microsoft.com/en-us/library/7tas5c80.aspx?cs-save-lang=1&cs-lang=vb
0
 

Author Comment

by:eq2006
ID: 38797378
sognoct--

Did you mean embed a DateTimePicker in the DataGridViewColumn?
0
 
LVL 9

Expert Comment

by:sognoct
ID: 38797411
Yes, it can be the simplest Solution
0
 
LVL 10

Accepted Solution

by:
Monica P earned 500 total points
ID: 38799990
Format as anyone type below

dataGridView1.Columns[0].DefaultCellStyle.Format = "MM'/'dd'/'yyyy";

OR

dataGridViewCellStyle.Format = "MM/dd/yyyy";
this.date.DefaultCellStyle = dataGridViewCellStyle;
// date being a System.Windows.Forms.DataGridViewTextBoxColumn
or
Refer this

http://stackoverflow.com/questions/7881085/convert-string-to-datetime-in-datagridview


Regular expression to check DateTime Format

http://www.aspdotnet-suresh.com/2012/07/regular-expression-to-validate-date-in.html
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now