Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Format Property

DataGridTextBoxColumn.Format Property

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

[Visual Basic]
Public Property Format As String
[C#]
public string Format {get; set;}
[C++]
public: __property String* get_Format();
public: __property void set_Format(String*);
[JScript]
public function get Format() : String;
public function set Format(String);

Property Value

The character or characters that specify how text is formatted.

Remarks

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.

Example

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.

[Visual Basic] 
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

[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";
}

[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 =
            dynamic_cast<DataGridTextBoxColumn*>(
            myDataGrid->TableStyles->Item[S"Orders"]->
            GridColumnStyles->Item[S"OrderAmount"]);
        myGridTextBoxColumn->FormatInfo = ItalyCultureInfo;
        myGridTextBoxColumn->Format = S"c";
    }

[JScript] 
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";
}

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DataGridTextBoxColumn Class | DataGridTextBoxColumn Members | System.Windows.Forms Namespace | CultureInfo | FormatInfo

Show:
© 2015 Microsoft