DataGridTextBoxColumn.Format 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定字元,指定如何格式化文字。
public:
property System::String ^ Format { System::String ^ get(); void set(System::String ^ value); };
public string Format { get; set; }
member this.Format : string with get, set
Public Property Format As String
屬性值
用來指定如何格式化文字的字元。
範例
下列範例會建立新的 CultureInfo 物件,並將它指派給 FormatInfo 物件的 屬性 DataGridTextBoxColumn 。 此範例也會將 Format 屬性設定為 「c」,以指定資料行應該將值顯示為貨幣。
private:
void ChangeColumnCultureInfo()
{
/* Create a new CultureInfo Object* using the
the locale ID for Italy. */
System::Globalization::CultureInfo^ ItalyCultureInfo = gcnew CultureInfo( 0x0410 );
/* Cast a column that holds numeric values to the
DataGridTextBoxColumn type, and set the FormatInfo
property to the new CultureInfo Object*. */
DataGridTextBoxColumn^ myGridTextBoxColumn =
dynamic_cast<DataGridTextBoxColumn^>(myDataGrid->TableStyles[ "Orders" ]->
GridColumnStyles[ "OrderAmount" ]);
myGridTextBoxColumn->FormatInfo = ItalyCultureInfo;
myGridTextBoxColumn->Format = "c";
}
private void ChangeColumnCultureInfo(){
/* Create a new CultureInfo object using the
the locale ID for Italy. */
System.Globalization.CultureInfo ItalyCultureInfo=
new CultureInfo(0x0410);
/* Cast a column that holds numeric values to the
DataGridTextBoxColumn type, and set the FormatInfo
property to the new CultureInfo object. */
DataGridTextBoxColumn myGridTextBoxColumn =
(DataGridTextBoxColumn) myDataGrid.TableStyles["Orders"].
GridColumnStyles["OrderAmount"];
myGridTextBoxColumn.FormatInfo = ItalyCultureInfo;
myGridTextBoxColumn.Format = "c";
}
Public Class Form1:Inherits Form
private myDataGrid as DataGrid
Public Shared Sub Main()
Dim t As New Form1()
' Write a purchase order.
End Sub
Private Sub ChangeColumnCultureInfo()
' Create a new CultureInfo object using the
' the locale ID for Italy.
Dim ItalyCultureInfo As CultureInfo = New _
CultureInfo(&H0410)
' Cast a column that holds numeric values to the
' DataGridTextBoxColumn type, and set the FormatInfo
' property to the new CultureInfo object.
Dim myGridTextBoxColumn As DataGridTextBoxColumn = _
CType( myDataGrid.TableStyles("Orders"). _
GridColumnStyles("OrderAmount"), DataGridTextBoxColumn)
myGridTextBoxColumn.FormatInfo = ItalyCultureInfo
myGridTextBoxColumn.Format = "c"
End Sub
備註
屬性 Format 會指定如何在資料行中顯示值。 例如,將 屬性設定為 「c」,以指定值會格式化為當地貨幣。 CultureInfo電腦的 會用來判斷實際貨幣格式。 變更資料時,這些值會自動自動格式化為原生類型。
如需格式化字元的詳細資訊,請參閱格式化類型和自訂日期和時間格式字串。
您套用的格式應該適用于資料類型。 例如,如果資料本質上是數值,請使用其中一個數值格式字串。
您可以將 屬性設定 FormatInfo 為使用適當文化特性識別碼建構的新 CultureInfo 實例,以變更 CultureInfoDataGridTextBoxColumn 的 。
若要設定 CultureInfo 應用程式的 ,請將 CurrentCulture 物件的 屬性 Application 設定為使用適當文化特性識別碼建構的新 CultureInfo 實例。