Many projects must deal with multiple cultures such as English, German and Japanese. The .NET Framework provides excellent support for multiple cultures, and this capability is passed through to the WinGrid™ user.
How do I format dates for different cultures?
Use a combination of Predefined formats and System.Globalization.CultureInfo objects to format the columns to any specific culture.
Commonly used Predefined number formats include:
Commonly used Predefined date formats include:
Warning: When using the .Format property of the WinGrid use the CultureInfo format characters, not the .NET "format" characters and character strings. If you want a short date, use "d" which is valid as a DateTimeFormat, the "Short Date" value is not valid for the CultureInfo object.
This sample project displays date columns for US English, German, and Japanese:
The UltraWinGrid Events Region contains the following event handlers:
UltraGrid1.InitializeLayout - The code in the InitializeLayout event tells the grid to fit the columns in the available space, right aligns the columns, creates a CultureInfo object for each of the three cultures, sets the date .Format and .FormatInfo properties:
In Visual Basic:
Imports System.Globalization Imports Infragistics.Win Imports Infragistics.Win.UltraWinGrid ... Private Sub UltraGrid1_InitializeLayout(ByVal sender As Object, _ ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) _ Handles UltraGrid1.InitializeLayout ' Fit columns e.Layout.AutoFitStyle = AutoFitStyle.ExtendLastColumn ' Create culture objects Dim cultureENUS As CultureInfo = CultureInfo.CreateSpecificCulture("en-us") Dim cultureDEDE As CultureInfo = CultureInfo.CreateSpecificCulture("de-de") Dim cultureJAJP As CultureInfo = CultureInfo.CreateSpecificCulture("ja-jp") ' Set date formats e.Layout.Bands(0).Columns("OrderDate").Format = "d" e.Layout.Bands(0).Columns("OrderDate").FormatInfo = cultureENUS e.Layout.Bands(0).Columns("RequiredDate").Format = "d" e.Layout.Bands(0).Columns("RequiredDate").FormatInfo = cultureDEDE e.Layout.Bands(0).Columns("ShippedDate").Format = "d" e.Layout.Bands(0).Columns("ShippedDate").FormatInfo = cultureJAJP End Sub
In C#:
using System.Globalization; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; ... private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { // Fit columns e.Layout.AutoFitStyle = AutoFitStyle.ExtendLastColumn; // Create culture objects CultureInfo cultureENUS = CultureInfo.CreateSpecificCulture("en-us"); CultureInfo cultureDEDE = CultureInfo.CreateSpecificCulture("de-de"); CultureInfo cultureJAJP = CultureInfo.CreateSpecificCulture("ja-jp"); // Set date formats e.Layout.Bands[0].Columns["OrderDate"].Format = "d"; e.Layout.Bands[0].Columns["OrderDate"].FormatInfo = cultureENUS; e.Layout.Bands[0].Columns["RequiredDate"].Format = "d"; e.Layout.Bands[0].Columns["RequiredDate"].FormatInfo = cultureDEDE; e.Layout.Bands[0].Columns["ShippedDate"].Format = "d"; e.Layout.Bands[0].Columns["ShippedDate"].FormatInfo = cultureJAJP; }
This sample project shows how to create CultureInfo objects and apply them to columns to display numbers and dates in different culture specific formats.