Solved

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

Posted on 2013-01-19
4
2,556 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

806 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