How to set datagridview column which is datetime to currentculture datetime format in c# ?

Darryl Hoar 181 Reputation points
2024-08-22T20:01:58.4166667+00:00

I have a datagridview on a winform's form. I need to set the format of one of the columns in the grid to the currentculture's datetime format.

I was doing (bad, I know)

testGrid.Columns[3].DefaultCellStyle.Format = "MM/dd/yyyy". But that doesn't work on a european system.

DateTimeFormatInfo dtFormat = CultureInfo.CurrentCulture.DateTimeFormat;

testGrid.Columns[3].DefaultCellStyle.Format = dtFormat doesn't work because it's not a string.

How do I crack this nut?

thanks for any help.

Developer technologies .NET Other
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2024-08-22T20:20:18.34+00:00

    Try this:

    testGrid.Columns[3].DefaultCellStyle.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.