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使用适当的区域性 ID 构造的新CultureInfo实例,可以更改CultureInfo该DataGridTextBoxColumn实例。
若要为应用程序设置 CultureInfo 属性,请将 CurrentCulture 对象的属性 Application 设置为使用适当的区域性 ID 构造的新 CultureInfo 实例。