Skip to main content Skip to footer

Fix Currency Symbols for SummaryRow Cells in C1DataGrid for WPF

Background:

WPF does not accept the current culture of the machine, and this is by design. It is because of this that the cells of a column follow WPF’s culture settings. However, cells in the C1DataGrid SummaryRow respect the current culture set by the system. This, however, can cause multiple currency symbols to appear when aggregating values in the SummaryRow. This article will show how to resolve this issue.

Steps to Complete:

To resolve this, we need to handle the LoadedCellPresenter event of the C1DataGrid. In the event handler, format the cell’s Text property with the appropriate culture settings. For this example we will use the US culture settings.

private void _grid_LoadedCellPresenter(object sender, C1.WPF.DataGrid.DataGridCellEventArgs e)
{
        if(e.Cell.Row.GetType()==typeof(DataGridSummaryRow))
        {
            double value = Convert.ToDouble(e.Cell.Text);
            CultureInfo usCulture = CultureInfo.GetCultureInfo("en-US");
            string valueInUS = string.Format(usCulture, "{0:C}", value);
               
            ((((e.Cell.Presenter.Content as StackPanel).Children))[0] as ContentPresenter).Content = valueInUS;
        }
}

Ruchir Agarwal