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. Image for the cookie policy date

InvariantInfo for date cell in GDBG

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

5 Replies

AD Administrator Syncfusion Team October 19, 2005 10:45 AM UTC

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;


AP Atith Pagdi October 19, 2005 11:01 AM UTC

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?


AP Atith Pagdi October 19, 2005 11:14 AM UTC

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".


AP Atith Pagdi October 19, 2005 12:45 PM UTC

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


AD Administrator Syncfusion Team October 19, 2005 01:48 PM UTC

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);
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon