Solved

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

Posted on 2013-01-19
4
2,677 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 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