Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataGridTextBoxColumn.Format Property

Gets or sets the character(s) that specify how text is formatted.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public string Format { get; set; }
/** @property */
public String get_Format ()

/** @property */
public void set_Format (String value)

public function get Format () : String

public function set Format (value : String)

Not applicable.

Property Value

The character or characters that specify how text is formatted.

The Format property specifies how values are displayed in the column. For example, set the property to "c" to specify that the values will be formatted as the local currency. 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 Date and Time Format Strings and Standard Numeric 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.

You can change the CultureInfo for a DataGridTextBoxColumn by setting the FormatInfo property to a new CultureInfo instance constructed with an appropriate culture 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.

The following example creates a new CultureInfo object and assigns it to the FormatInfo property of a DataGridTextBoxColumn object. 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= 
   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";
}

private void ChangeColumnCultureInfo()
{
    /* Create a new CultureInfo object using the the locale ID for Italy.*/
    System.Globalization.CultureInfo ItalyCultureInfo = 
        new CultureInfo(0x410);

    /* 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.get_TableStyles().
        get_Item("Orders").get_GridColumnStyles().
        get_Item("OrderAmount")));

    myGridTextBoxColumn.set_FormatInfo(ItalyCultureInfo);
    myGridTextBoxColumn.set_Format("c");
} //ChangeColumnCultureInfo

private function ChangeColumnCultureInfo(){
   // Create a new CultureInfo object using the 
   // the locale ID for Italy. 
   var ItalyCultureInfo : System.Globalization.CultureInfo = new CultureInfo(0x0410);
     
   // Cast a column that holds numeric values to the   
   // DataGridTextBoxColumn type, and set the FormatInfo
   // property to the new CultureInfo object. 
   var myGridTextBoxColumn : DataGridTextBoxColumn = 
   DataGridTextBoxColumn(myDataGrid.TableStyles["Orders"].
   GridColumnStyles["OrderAmount"]);
   
   myGridTextBoxColumn.FormatInfo = ItalyCultureInfo;
   myGridTextBoxColumn.Format = "c";
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

Show:
© 2014 Microsoft