• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2209
  • Last Modified:

Controlling date formats in DataGridView

In a DataGridView column, I have set the cell template date format style to "yyyy/MM/dd", but as soon as I click on the new line, that date format reverts to the system short date format ("dd/MM/yyy").  Here is my code:

_notesGrid.Columns["NotesDate"].CellTemplate.Style.Format = "yyyy/MM/dd";

What extra code must I add to avoid this and get all the dates appearing as "yyyy/MM/dd"?
0
corebiz
Asked:
corebiz
  • 2
1 Solution
 
Jai STech ArchCommented:
if the grid is binded to a data source...
better way is to write the formatting in the query...so that you dont need to set your style in the grid...
0
 
Jai STech ArchCommented:
hope this helps...

http://vbcity.com/forums/topic.asp?tid=148613

To do what you want to do, simply make a handler for the ItemDataBound event for the data grid row, and use a String.Format(fmt,arg) call to impose your desired formating. As it's read only, you don't need to create your own parse override routine for a custom text edit control.
0
 
shilpa_JbCommented:
Hi,
 check this link if this helps you..
http://msdn2.microsoft.com/en-us/library/ha5xt0d9.aspx

Cheers!
-Shilpa
0
 
corebizAuthor Commented:
Thanks for your input.

After running around in circles for another 3 hours, I discovered the DefaultValuesNeeded event and used that to assign the value in exactly the format I wanted.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now