473,604 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread.CurrentT hread.CurrentCu lture problem

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.CurrentT hread.CurrentCu lture = new CultureInfo("en-US", false );

Thread.CurrentT hread.CurrentCu lture.DateTimeF ormat.DateSepar ator = "/";

Thread.CurrentT hread.CurrentCu lture.DateTimeF ormat.ShortDate Pattern =
"d/M/yyyy";

Thread.CurrentT hread.CurrentCu lture.NumberFor mat.NumberGroup Separator = ",";

Thread.CurrentT hread.CurrentCu lture.NumberFor mat.NumberDecim alSeparator =
".";

Thread.CurrentT hread.CurrentUI Culture = Thread.CurrentT hread.CurrentCu lture;


Sep 26 '06 #1
5 17397
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.CurrentT hread.CurrentCu lture = new CultureInfo("en-US", false );

Thread.CurrentT hread.CurrentCu lture.DateTimeF ormat.DateSepar ator = "/";

Thread.CurrentT hread.CurrentCu lture.DateTimeF ormat.ShortDate Pattern = "d/M/yyyy";

Thread.CurrentT hread.CurrentCu lture.NumberFor mat.NumberGroup Separator = ",";

Thread.CurrentT hread.CurrentCu lture.NumberFor mat.NumberDecim alSeparator = ".";

Thread.CurrentT hread.CurrentUI Culture = Thread.CurrentT hread.CurrentCu lture;


Sep 26 '06 #2
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.Current Thread.CurrentC ulture = new CultureInfo("en-US", false );

Thread.Current Thread.CurrentC ulture.DateTime Format.DateSepa rator = "/";

Thread.Current Thread.CurrentC ulture.DateTime Format.ShortDat ePattern =
"d/M/yyyy";

Thread.Current Thread.CurrentC ulture.NumberFo rmat.NumberGrou pSeparator =
",";

Thread.Current Thread.CurrentC ulture.NumberFo rmat.NumberDeci malSeparator =
".";

Thread.Current Thread.CurrentU ICulture =
Thread.Current Thread.CurrentC ulture;



Sep 27 '06 #3
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;




Sep 27 '06 #4
Thanks Dave Sexton,

I use your methos and put in my program.cs, it does not work. My program.cs
code in like below, does it any mistake on my code.

static class Program

{

[STAThread]

static void Main()

{

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;

Application.Ena bleVisualStyles ();

Application.Set CompatibleTextR enderingDefault (false);

Application.Run (new Main());

}

}

Sep 29 '06 #5
Sorry, Dave Sexton,

It work for me now, I got to set the DataGridView format to "d"

Thank you.
Sep 29 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4502
by: Jesper Matthiesen | last post by:
Hey In the run method of an io-thread I saw this: while(Thread.currentThread() == thread) { ... } Where 'thread' is an instance variable. What is the purpose of this check? Regards Jesper
5
3144
by: Clive | last post by:
Hi, I have an ASPX app that checks the Culture of the machine. My PC is currently set to have English(US) dates and US Currency. When I check the Culture it returns "en-IE". The machine did have this original setting but I changed
1
2343
by: Rahul Agarwal | last post by:
Hi I am trying to write data back to the client using dataset.WriteXML and I have set the Thread.CurrentThread.CurrentCulture to "no" (norwegian) just before writing the data using WriteXML. But dataset.WriteXML dosent seems to be using the CurrentCulture settings and still writes dates, numeric values using the original settings. My Code...
1
1710
by: Clive | last post by:
Hi, I have an ASPX app that checks the Culture of the machine. My PC is currently set to have English(US) dates and US Currency. When I check the Culture it returns "en-IE". The machine did have this original setting but I changed
2
2118
by: shipcreak | last post by:
I have an interesting problem with a sort of producer-consumer system for error logging. Consider the following code: <code> SyncLock _eventList.SyncRoot Dim item As ExceptionLogEntry ' If there are items, get the top one If _eventList.Count > 0 Then
3
1526
by: Paul Rubin | last post by:
As I understand it, generators are supposed to run til they hit a yield statement: import time def f(): print 1 time.sleep(3) for i in range(2,5): yield i
1
1744
by: Andrue Cope | last post by:
Hi, We have a strange problem. We are invoking the FolderBrowseDialog and have found that if we cancel that dialog within a few seconds of it appearing it causes one of our (completely unrelated) background threads to hang on program shut down. Details: Background thread is sitting idle waiting for work. This thread has nothing to with the folder selection activity - it's a completely
2
3986
by: spig.marco | last post by:
Hi to all!, I've downloaded .net Framework SDK 2.0 and I have VB.NET2005 Express Edition, I would like to create multilanguage systems that changes with radio button. With Windows Localization Resource I changed the label of my FrmMain.vb! and created automaticaly FrmMain.en.resx. When i lunch the command in FrmMain_load() .... Thread.CurrentThread.CurrentUICulture = New CultureInfo("en")
4
3603
by: Rainer Queck | last post by:
Hi NG, in my application a <myDataTable>.Select fails with "Syntax error in the expression." It took me a while, isolate the cause to this: To select some datarows from a data table I am using a select sting like "selectStr = String.Format("x >= {0}", aDoubleVar)". The Thread.CurrentThread.CurrenCulture is set to "en-US" where the Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator is
0
8419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8409
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8065
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8280
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5882
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3907
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3955
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.