Localizing Cell Display Format
참고하기
원본: http://help.infragistics.com/Help/NetAdvantage/NET/2008.3/CLR2.0/html/WinGrid_Localizing_Cell_Display_Format.html
간단 요약하면~
C: 화폐단위
D: 소수점구현 가능
N: 숫자형(부동소주점 없음)
Background
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.
Questions
- How do I format dates for different cultures?
Solutions
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:
Format Character | Description and Associated Properties |
---|---|
c, C | Currency format |
d, D | Decimal format. |
e, E | Scientific (exponential) format. |
f, F | Fixed-point format. |
g, G | General format. |
n, N | Number format |
r, R | Roundtrip format, which ensures that numbers converted to strings will have the same value when they are converted back to numbers. |
x, X | Hexadecimal format. |
Commonly used Predefined date formats include:
Format Character | Associated Property/Description | Example Format Pattern (en-US) |
---|---|---|
d | ShortDatePattern | MM/dd/yyyy |
D | LongDatePattern | dddd, dd MMMM yyyy |
f | Full date and time (long date and short time) | dddd, dd MMMM yyyy HH:mm |
F | FullDateTimePattern (long date and long time) | dddd, dd MMMM yyyy HH:mm:ss |
g | General (short date and short time) | MM/dd/yyyy HH:mm |
G | General (short date and long time) | MM/dd/yyyy HH:mm:ss |
m, M | MonthDatePattern | MMMM dd |
r, R | RFC1123Pattern | ddd, dd MMM yyyy HH':'mm':'ss 'GMT' |
s | SortableDateTimePattern (based on ISO 8601) using local time | yyyy'-'MM'-'dd'T'HH':'mm':'ss |
t | ShortTimePattern | HH:mm |
T | LongTimePattern | HH:mm:ss |
u | UniversalSortableDateTimePattern using universal time | yyyy'-'MM'-'dd HH':'mm':'ss'Z' |
U | Full date and time (long date and long time) using universal time | dddd, dd MMMM yyyy HH:mm:ss |
y, Y | YearMonthPattern | yyyy MMMM |
Sample Project
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.GlobalizationImports
Infragistics.WinImports
Infragistics.Win.UltraWinGrid ...Private Sub
UltraGrid1_InitializeLayout(ByVal
senderAs Object
, _ByVal
eAs
Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) _Handles
UltraGrid1.InitializeLayout' Fit columns
e.Layout.AutoFitStyle = AutoFitStyle.ExtendLastColumn' Create culture objects
Dim
cultureENUSAs
CultureInfo = CultureInfo.CreateSpecificCulture("en-us")Dim
cultureDEDEAs
CultureInfo = CultureInfo.CreateSpecificCulture("de-de")Dim
cultureJAJPAs
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 = cultureJAJPEnd 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; }
Review
This sample project shows how to create CultureInfo objects and apply them to columns to display numbers and dates in different culture specific formats.