We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

InvariantInfo for date cell in GDBG

Thread ID:





36051 Oct 19,2005 06:33 AM Oct 19,2005 09:48 AM Windows Forms 5
Tags: GridControl
Atith Pagdi
Asked On October 19, 2005 06:33 AM

Hi, I''ve specified the date format for a cell of the GDBG as follows: this.dgTest.Binder.InternalColumns["ProjStatusDate"].StyleInfo.Format = "dd-MMM-yyyy"; This works great. But when I change the language settings in control panel to Japanese, it displays 19-10-2005 instead of 19-Oct-2005 (this is how I want it). To tackle this, I tried: this.dgTest.Binder.InternalColumns["ProjStatusDate"].StyleInfo.CultureInfo.DateTimeFormat = DateTimeFormatInfo.InvariantInfo; but I get an "Object reference not set to an instance of an object" error. Any ideas why this is happening and how I can achieve my end result? Thanks, Atith

Administrator [Syncfusion]
Replied On October 19, 2005 06:45 AM

What is null? Try first creating the CultureInfo object, say cultureInfo1, and set its properties the way you want them. Then set: this.dgTest.Binder.InternalColumns["ProjStatusDate"].StyleInfo.CultureInfo = cultureInfo1;

Atith Pagdi
Replied On October 19, 2005 07:01 AM

Don''t know. The run fails at this statement. The aim is to have a date format independent of the culture. That''s why I''m trying to set the CultureInfo.DateFormatInfo to the Invariant value and this fails! If I declare a culture info object as CultureInfo ci = new CultureInfo(); I get an error. Do I need to specify something in the paranthesis in the constructor? All I want to do is: CultureInfo ci = new CultureInfo(); //is this correct? ci.DateTimeFormat = DateTimeFormatInfo.InvariantInfo; this.dgTest.Binder.InternalColumns["ProjStatusDate"].StyleInfo.CultureInfo = ci; Any ideas how I can do this?

Atith Pagdi
Replied On October 19, 2005 07:14 AM

I declared CultureInfo as follows: CultureInfo ci = new CultureInfo("en-US"); ci.DateTimeFormat = DateTimeFormatInfo.InvariantInfo; And then specified the culture info for the cell as follows: this.dgTest.Binder.InternalColumns["ProjStatusDate"].StyleInfo.CultureInfo = ci; this.dgTest.Binder.InternalColumns["ProjStatusDate"].StyleInfo.Format = "dd-MMM-yyyy"; But the date still shows up as "19-10-2005".

Atith Pagdi
Replied On October 19, 2005 08:45 AM

Also, is there any way I can override the culture info for the cell so that it always displays dates in the "dd-MMM-yyyy" format irrespective of the local settings? Thanks, Atith

Administrator [Syncfusion]
Replied On October 19, 2005 09:48 AM

You can check the .NET documentation on CultureInfo to see how to use its contructor. If you always want the same format not matter what the local setting, try handling the DrawCellDisplayText event.
private void gridDataBoundGrid1_DrawCellDisplayText(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellDisplayTextEventArgs e)
	if(e.Style.Format == "dd-MMM-yy" && e.Style.CellValue != null && e.Style.CellValue is DateTime)
		DateTime dt = (DateTime)e.Style.CellValue;
		e.DisplayText = dt.ToString(e.Style.Format, System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.