New to Telerik UI for WinForms? Download free 30-day trial

Data Formatting

RELATED VIDEOS
Formatting Data In RadGridView for WinForms.
In this RadTip, John Kellar demonstrates how you can apply custom formatting to data within a RadGridView for Windows Forms. (Runtime: 09:14)

GridViewDataColumn allows you to format the data displayed in it. You can control that by setting the FormatString, FormatInfo and NullValue properties of the column.

The FormatString property determines how the cell values are formatted as strings. The property is applicable with Microsoft Formatting Syntax. For more information, see the Formatting Overview chapter in MSDN.

The FormatInfo property provides the culture in which the string formatting is applied.

By setting the NullValue property, you determine the value that appears if the cell value is null.

Here is a sample covering these properties:

Formatting data

GridViewDecimalColumn unitPriceColumn = this.radGridView1.Columns["UnitPrice"] as GridViewDecimalColumn;
unitPriceColumn.FormatString = "Price: {0:C}";
unitPriceColumn.FormatInfo = CultureInfo.CreateSpecificCulture("en-GB");
unitPriceColumn.NullValue = 0;

Dim unitPriceColumn As GridViewDecimalColumn = TryCast(Me.RadGridView1.Columns("UnitPrice"), GridViewDecimalColumn)
        unitPriceColumn.FormatString = "Price: {0:C}"
        unitPriceColumn.FormatInfo = CultureInfo.CreateSpecificCulture("en-GB")
        unitPriceColumn.NullValue = 0

Figure 1: The data in the middle is formated.

WinForms RadGridView Formated Middle Data

Note that the value of the NullValue property should be the same as its column data type.

The WrapText property wraps text if the text is wider than the column width.

The TextAlignment property defines the text alignment for the column.

Using the column text properties

GridViewDataColumn productNameColumn = this.radGridView1.Columns["ProductName"];
productNameColumn.WrapText = true;
productNameColumn.TextAlignment = ContentAlignment.BottomRight;

Dim productNameColumn = Me.RadGridView1.Columns("ProductName")
productNameColumn.WrapText = True
productNameColumn.TextAlignment = ContentAlignment.BottomRight

See Also

In this article