Hi,
I tested the following code and it worked for me:
CultureInfo culture = new CultureInfo("en-US");
culture.DateTim eFormat.ShortDa tePattern = "d/M/yyyy";
culture.DateTim eFormat.ShortTi mePattern = string.Empty;
System.Threadin g.Thread.Curren tThread.Current Culture = culture;
System.Threadin g.Thread.Curren tThread.Current UICulture = culture;
The reason why you need to set the ShortDatePatter n and ShortTimePatter n strings is because the DateTimeConvert er, which is used by
the DataGridView cell that is formatting the DateTime into a string, uses the CurrentCulture to format the date in the general,
short-time format (g). The general format uses these two properties and concatenates the time to the date. Unfortunately, the
resulting string has a trailing space which seems to be unavoidable due to the string.Empty assignment, which removes the time from
the general format.
DateTime formatting on MSDN:
http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx
For finer-grained control over the formatting of DateTimes in each cell of the DataGridView you must use the CellFormatting event as
I mentioned previously.
--
Dave Sexton
"Tsair" <ls****@streamy x.comwrote in message news:ef******** ******@TK2MSFTN GP06.phx.gbl...
>I have to set Each DataGridView.Ce llFormatting, is that any way to set the
Date Format to effect the whole application.
Thank you.
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:eq******** ******@TK2MSFTN GP05.phx.gbl...
>Hi,
Try adding an event handler to the DataGridView.Ce llFormatting event. Here you can specify any format that you want.
--
Dave Sexton
"Tsair" <ls****@streamy x.comwrote in message news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>>>I set the thread culture in MAIN() as below in order to show the date in format DAY/MONTH/YEAR, but the datagridview alway show
the date in M/d/yyyy.
How to set the default Date format from windows xp control panel by C# coding or is that any way to set the application date
format to d/M/yyyy without change the windows xp regional setting ?
Thread.Curren tThread.Current Culture = new CultureInfo("en-US", false );
Thread.Curren tThread.Current Culture.DateTim eFormat.DateSep arator = "/";
Thread.Curren tThread.Current Culture.DateTim eFormat.ShortDa tePattern = "d/M/yyyy";
Thread.Curren tThread.Current Culture.NumberF ormat.NumberGro upSeparator = ",";
Thread.Curren tThread.Current Culture.NumberF ormat.NumberDec imalSeparator = ".";
Thread.Curren tThread.Current UICulture = Thread.CurrentT hread.CurrentCu lture;