DataGridTextBoxColumn.Format Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Property Value
The character or characters that specify how text is formatted.
Examples
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 = 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
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 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.
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.