DataGridTextBoxColumn.FormatInfo 属性

定义

获取或设置用于确定格式化值的方法的特定区域性信息。Gets or sets the culture specific information used to determine how values are formatted.

public:
 property IFormatProvider ^ FormatInfo { IFormatProvider ^ get(); void set(IFormatProvider ^ value); };
[System.ComponentModel.Browsable(false)]
public IFormatProvider FormatInfo { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.FormatInfo : IFormatProvider with get, set
Public Property FormatInfo As IFormatProvider

属性值

IFormatProvider

实现 IFormatProvider 接口的一个对象,如 CultureInfo 类。An object that implements the IFormatProvider interface, such as the CultureInfo class.

属性

示例

下面的示例创建一个新的 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 属性设置为某个格式设置字符时,将 DataGridTextBoxColumn 使用属性提供的信息 FormatInfo 来进一步指定要使用的特定于区域性的格式设置。When setting the Format property to one of the formatting characters, the DataGridTextBoxColumn uses the information provided by the FormatInfo property to further specify what cultural-specific formatting to use. 例如,如果将 Format 属性设置为 "c" 格式为 "c" ("货币") ,则可以进一步指定使用里拉的符号。For example, when the Format property is set to the format character "c" (for currency), you can further specify that the symbol for the lira be used. 为此,请创建一个 CultureInfo 具有意大利区域设置 ID 的新对象,然后将 FormatInfo 属性设置为新的 CultureInfo 对象。To do this, create a new CultureInfo object with the locale ID for Italy, and set the FormatInfo property to the new CultureInfo object.

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

适用于

另请参阅