DataGridTextBoxColumn.Format 属性

定义

获取或设置指定格式化文本的方法的一个或多个字符。Gets or sets the character(s) that specify how text is formatted.

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

属性值

String

指定格式化文本的方法的一个或多个字符。The character or characters that specify how text is formatted.

示例

下面的示例创建一个新的 CultureInfo 对象,并将其分配给 FormatInfo 对象的属性 DataGridTextBoxColumnThe following example creates a new CultureInfo object and assigns it to the FormatInfo property of a DataGridTextBoxColumn object. 该示例还将 Format 属性设置为 "c",以指定该列应将值显示为货币。The example also sets the Format property to "c" to specify that the column should display values as currency.

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属性指定如何在列中显示值。The Format property specifies how values are displayed in the column. 例如,将属性设置为 "c" 可指定将值设置为本地货币格式。For example, set the property to "c" to specify that the values will be formatted as the local currency. 计算机的用于 CultureInfo 确定实际货币格式。The CultureInfo for the computer is used to determine the actual currency format. 更改数据时,这些值将自动无格式地转换为本机类型。The values are automatically unformatted to the native type when data is changed.

有关设置字符格式的详细信息,请参阅 格式设置类型自定义日期和时间格式字符串For more information about formatting characters, see Formatting Types and Custom Date and Time Format Strings.

所应用的格式应该适用于数据类型。The format you apply should be appropriate to the data type. 例如,如果数据在性质上是数字,请使用其中一个数值格式字符串。For example, if the data is numeric in nature use one of the numeric format strings.

可以 CultureInfo DataGridTextBoxColumn 通过将 FormatInfo 属性设置为 CultureInfo 使用适当区域性 ID 构造的新实例来更改的。You can change the CultureInfo for a DataGridTextBoxColumn by setting the FormatInfo property to a new CultureInfo instance constructed with an appropriate culture ID.

若要为 CultureInfo 应用程序设置,请将 CurrentCulture 对象的属性设置 ApplicationCultureInfo 使用适当区域性 ID 构造的新实例。To set the CultureInfo for the application, set the CurrentCulture property of the Application object to a new CultureInfo instance constructed with an appropriate culture ID.

适用于

另请参阅