Articles in this section
Category / Section

How to use NumberFormatInfo in the SummaryColumn of the GridTableSummaryRow in WPF Grid?

1 min read

In the WPF DataGrid, you can use NumberFormatInfo in the SummaryColumn of the GridTableSummaryRow by deriving a new class from GridTableSummaryCellRenderer and override its OnUpdateEditBinding virtual method. 

 

Note:

By default, summary result is displayed based on the Format specified in SummaryColumn.

 

C#:

public class GridTableSummaryCellRendererExt : GridTableSummaryCellRenderer
    {
        public override void OnUpdateEditBinding(DataColumnBase column, Syncfusion.UI.Xaml.Grid.GridTableSummaryCell element, object dataContext)
        {
            //Check whether the datacontext is SummaryRecordEntry
            var record = dataContext as SummaryRecordEntry;
            if (!(dataContext is SummaryRecordEntry))
                return;
 
            //Process each SummaryColumn and get the display text of corresponding summary
            foreach (ISummaryColumn summaryColumn in record.SummaryRow.SummaryColumns)
            {
                if (!summaryColumn.MappingName.Contains(column.GridColumn.MappingName))
                    continue;
 
                string summarytext = string.Empty;
                if (record.SummaryRow.ShowSummaryInRow)
                    summarytext = SummaryCreator.GetSummaryDisplayTextForRow(record, this.DataGrid.View);
                else
                    summarytext = SummaryCreator.GetSummaryDisplayText(record, column.GridColumn.MappingName, this.DataGrid.View);
 
                if (!string.IsNullOrEmpty(summarytext))
                {
                    //Create new number format and apply it to summary columns 
                    NumberFormatInfo format = new NumberFormatInfo();
                    format.NumberDecimalDigits = 3;
                    format.NumberDecimalSeparator = "*";
                    format.NumberGroupSeparator = ",";
                    //Number format is applied to summary columns
                    element.Content = Convert.ToDouble(double.Parse(summarytext, NumberStyles.Currency)).ToString("N", format);
                }
            }
        }
    }

Refer to the following code example to remove the default GridTableSummaryCellRenderer and add the customized GridTableSummaryCellRendererExt to the renderer’s collection in the SfDataGrid.

C#

public MainWindow()
{
    InitializeComponent();
    //Customized GridTableSummaryCellRendererExt is added to the CellRenderers collection
    grid.CellRenderers.Remove("TableSummary");
    grid.CellRenderers.Add("TableSummary", new GridTableSummaryCellRendererExt()); 
}

 

The above formatting is applied to summary values as follows.

NumberFormatInfo is applied to summary values

Figure 1:NumberFormatInfo is applied to summary values

 

Sample Links:

WPF

 

WinRT

 

WP

 

UWP

 


Conclusion

I hope you enjoyed learning about how to use NumberFormatInfo in the SummaryColumn of the GridTableSummaryRow in WPF Grid.

You can refer to our WPF Grid feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Grid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you! 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied