Articles in this section

How to format the color of summary row based on specific conditions?

The GridDatacontrol’s QueryCellInfo event helps you to customize the colour of summary row based on certain conditions. If you have two or more summaries, you can customize the particular summary row through conditions.

You can refer the following code sample to setup Background and Foreground colour for summary row.

XAML

<syncfusion:GridDataControl Name="dataGrid"

                                    AllowDragColumns="True"

                                    AllowEdit="True"

                                    AllowGroup="True"

                                    AutoPopulateColumns="False"

                                   ItemsSource="{Binding GDCSource}"

                                 ShowTableSummaries="True">

  < syncfusion:GridDataControl.TableSummaryRows>

   <syncfusion:GridDataSummaryRow Title="Total : {total salary}"

                                               ShowSummaryInRow="False"

                                               TitleColumnCount="1">

        <syncfusion:GridDataSummaryRow.SummaryColumns>

          <syncfusion:GridDataSummaryColumn Name="total salary"

                                                          Format="'{Sum:c}'"

                                                          MappingName="Salary"

                                                          SummaryType="DoubleAggregate" />

                    </syncfusion:GridDataSummaryRow.SummaryColumns>

        </syncfusion:GridDataSummaryRow> </syncfusion:GridDataControl.TableSummaryRows>

C#

this.dataGrid.Model.QueryCellInfo += new Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventHandler(Summary_QueryCellInfo);
// to change BG of summary
  private void Summary_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
        {
            var style = e.Style as GridDataStyleInfo;
  //ResolveIndexToSummaryPosition method is used to resolve Index of TableSummary from Cell RowIndex value.
var summaryrowindex = this.dataGrid.Model.ResolveIndexToSummaryPosition(e.Cell.RowIndex);
            if (summaryrowindex >= 0 && this.dataGrid.Model.View != null)
            { 
//Checking whether the column name is “Salary” and then formatting the color of summary.
                 if (style.CellIdentity.Column != null && style.CellIdentity.Column.MappingName.Equals("Salary"))
                {
                    var summaryrow = this.dataGrid.Model.View.Records.TableSummaries[summaryrowindex];
                    var sumaggregate = summaryrow.SummaryValues[0].AggregateValues["Sum"];
 
                    var actualval = double.Parse(sumaggregate.ToString());
                   if( actualval > 200000.00 && actualval < 400000.00)
                    {
                        e.Style.Background = Brushes.Yellow;
                        e.Style.Foreground = Brushes.Red;
                    }
                }
            }
        }

The following screen shot shows the output for the above code in the GridDataControl.

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