Skip to main content

Tutorial: Format Summary Text

  • 3 minutes to read

This walkthrough is a transcript of the Format Summary Text video available on the DevExpress YouTube Channel.

In this tutorial, you will learn how to add custom text to summary values, what kind of value formatting is applied to summaries by default, how to change numeric value formatting using an example of a total summary, and how to change formatting for date-time values using an example of group summaries.

Starting Point

Start with a GridControl that has a footer enabled.

GridView_Summaries_InitialGridForFormatSummary

Add Custom Text to Summary Values

GridView_Summaries_CountSummaryDisplayFormat

  • Run the application. The footer cell under the Product Name column now shows the total record count along with the specified text.

GridView_Summaries_CountSummaryWithCustomText

Format Numeric Total Summary Values

  • Open the Property grid displaying the OrderSum column settings.
  • Expand the GridColumn.SummaryItem property and set the summary type to SummaryItemType.Sum. The GridSummaryItem.DisplayFormat property is automatically changed. The created summary format string already contains custom text and the value placeholder additionally includes a format specifier - c2 – meaning currency formatting with two digits after the decimal point.

GridView_Summaries_SumSummaryDefaultFormat

  • Set the format specifier to c0 to hide decimal digits.

GridView_Summaries_SumSummaryChangingFormat

To learn more about available numeric format specifiers, refer to the Standard Numeric Format Strings topic in MSDN.

Format Date-Time Group Summary Values

GridView_Summaries_GroupDateSummaryDisplayFormat

  • Run the application to see the result.

GridView_Summaries_GroupDateSummaryFormatResult

Example: How to Custom Format Summary Values

gridView.Columns["MyColumn"].SummaryItem.Format = new MyFormat();  

public class MyFormat : IFormatProvider, ICustomFormatter {  
    public string Format(string format, object arg, IFormatProvider formatProvider) {
        // Convert argument to a string.
        string result = arg.ToString();

        // Format the result as needed.
        // ...

        return result;  
    }  
    public object GetFormat(Type formatType) {  
        if (formatType == typeof(ICustomFormatter))  
            return this;  
        else  
            return null;  
    }  
}

Read the following topic for detailed information: IFormatProvider Interface.

See Also