We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Formatting Conditional GridSummaryRowDescriptor

How can i format conditional a GridSummaryRowDescriptor?. I have a collections of GridSummaryColumnDescriptor into my GridSummaryRowDescriptor. I need to change the color of the SummaryRows deppending the value of one colum. 

For exemple, I have Col1,Col2 and Col3 as range into my GridSummaryRowDescriptor. When Col2 > 0 all the row must be with backColor in green, else in red.

I can format all the cells of my GridGroupingControl, except  the  GridSummaryRowDescriptor. I get this with:

 GridConditionalFormatDescriptor format1 = new GridConditionalFormatDescriptor();     
            format1.Appearance.AnyRecordFieldCell.BackColor = Color.LimeGreen;
            format1.Expression = "[$Col2]  > 0";
            format1.Name = "ConditionalFormat 1";

            GridConditionalFormatDescriptor format2 = new GridConditionalFormatDescriptor();           
            format2.Appearance.AnyRecordFieldCell.BackColor = Color.Firebrick;
            format2.Expression = "[$Col2]  <= 0";
            format2.Name = "ConditionalFormat 2";
            
            this.dgReporte.TableDescriptor.ConditionalFormats.Add(format1);
            this.dgReporte.TableDescriptor.ConditionalFormats.Add(format2); 

This works, but not work with my  sumatory Rows. How can i get it? Thanks

8 Replies

AK Arun Kumar V Syncfusion Team January 22, 2013 07:40 AM UTC

Hi Sergio,

Thanks for your interest in syncfusion products.

Query:

Format the gridSummary row descriptor

If you want to customize the backcolor of a GridSummaryRow descriptor, please make use of the following UG links for better understanding.

UG Link:1. http://help.syncfusion.com/ug/windows%20forms/grid/default.htm#!documents/exploringsummaries.htm

http://help.syncfusion.com/ug/windows%20forms/grid/default.htm#!documents/43442conditionalformatting.htm

Please let me know if you have any other concerns.

Regards,

Arun.



SE Sergio January 22, 2013 11:11 PM UTC

In fact I had already checked those pages, With that solution, i got to format all the rows, except the SummaryRows when group any column. One solution is to get the values form a  Sum colum in SumaryRow, and the i can apply the format, but i cant get values yet. Thanks for the help.Attached a picture of the result

Error_19a0e5e1.rar


AK Arun Kumar V Syncfusion Team January 28, 2013 05:33 AM UTC

Hi Serigo,

Thanks for the update.

Query:

Summary row back color

Sorry for the delay. There are some network problem in updating. To change the summary row backcolor. You have to create instances for the summary row descriptor. And using it you can change the color of the summary row. Regarding achieving the behavior while formatting rows, please customize your conditions in querysellstyleinfo event. Please make use of the attached sample.

Code Snippet:

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)

        {

 

//Please check your conditions here(i.e: when you ant to change the color of summary row descriptor...

            if (e.TableCellIdentity.TableCellType == GridTableCellType.SummaryFieldCell)//e.TableCellIdentity.TableCellType == Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellType.AnySummaryCell)

            {

                srd.Appearance.AnyCell.HorizontalAlignment = GridHorizontalAlignment.Right;

                srd.Appearance.AnyCell.BackColor = Color.Red;

 

                srd.Appearance.AnyCell.HorizontalAlignment = GridHorizontalAlignment.Right;

                srd.Appearance.AnyCell.BackColor = Color.Green;

            }

        }

Please let me know if you have any other concerns.

Regards,

Arun.



CS_39796b40.zip


SE Sergio January 29, 2013 04:43 PM UTC

Ok, but i repeat again, i need format the colors DEPENDING OF A VALUE containing the sum Row, how can i get it? I need the value from a column to determinate the color of my Sumatory Row.


AS Athiram S Syncfusion Team January 30, 2013 07:21 AM UTC

Hi Sergio,

Thanks for your update.

You can make use of "QueryCellInfo" event to color the summary row.

In order to color the cells based on the condition column>value, you can make use of the following code in event:

if (e.TableCellIdentity.TableCellType == GridTableCellType.SummaryFieldCell)//e.TableCellIdentity.TableCellType == Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellType.AnySummaryCell)
            {
                if(e.TableCellIdentity.ColIndex>2)
               
                grid.Appearance.AnyCell.BackColor = Color.Black;
                else
              
                grid.Appearance.AnyCell.BackColor = Color.Green;
            }

Please let me know if you have  any concerns.

Regards,
Athiram S



VK Vinish Kumar K Syncfusion Team January 31, 2013 11:15 AM UTC

HI Sergio,

 

Sorry for the inconvenience caused with delay.

 

Query

Formatting the summary row.

We have analyzed your query. The GridConditionalFormatDescriptor class provide support to apply formats based on the expression in which the column will keep track only the record values. Hence, the conditional formats cannot be applied for summaryrow and summarycaptionrow.

 

However, you can apply the formats based on condition to the summary row by handling the QueryCellStyleInfo event. Here is some code for your reference in which this has been done.

 

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)

        {

            if (e.TableCellIdentity.TableCellType == GridTableCellType.SummaryFieldCell)

            {

                Element el = e.TableCellIdentity.DisplayElement;

                GridTable table = e.TableCellIdentity.Table;

                GridSummaryRow row = e.TableCellIdentity.DisplayElement as GridSummaryRow;

                GridSummaryRowDescriptor summaryRowDescriptor = row.SummaryRowDescriptor;

                GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns[0];

                if (el.Kind == DisplayElementKind.Summary)

                {

                    if (sumCol1 != null)

                    {

                        string text1 = sumCol1.GetDisplayText(table, row);

                        double value = double.Parse(text1);

                        if (e.TableCellIdentity.SummaryColumn.Name == "QuantityTotal" && value > 10)

                        {

                            summaryRowDescriptor.Appearance.AnyCell.BackColor = Color.Red;

                        }

                        if (e.TableCellIdentity.SummaryColumn.Name == "QuantityDistinctCount" && value >= 50)

                        {

                            summaryRowDescriptor.Appearance.AnyCell.BackColor = Color.White;

                            e.Style.TextColor = Color.Blue;

                        }

                        if (e.TableCellIdentity.SummaryColumn.Name == "QuantityMedian" )

                        {

                            summaryRowDescriptor.Appearance.AnyCell.BackColor = Color.Green;

                        }

                    }

                }

            }

        }

Please refer the attached sample file also which is modified with the above codes.

We hope this will help to you to implement the same behavior in your application.

 

Please let me know if you need more information about this.

 

Regards,

Vinish.



CS_70eac15f.zip


SE Sergio January 31, 2013 04:36 PM UTC

I downloaded the example, but does not work, it inherits a class called Metroform, which is not in the project.

Also implemented the proposed solution, but when entering the method QueryCellStyleInfo, property e.TableCellIdentity.TableCellType never equals to GridTableCellType.SummaryFieldCell 

The way I'm using as SumRow is:

 GridSummaryColumnDescriptor scd1 = new GridSummaryColumnDescriptor("Sum1", SummaryType.DoubleAggregate, "$Meta", "{Sum:$###,###,##0.00}");
            GridSummaryColumnDescriptor scd2 = new GridSummaryColumnDescriptor("Sum2", SummaryType.DoubleAggregate, "$Cobrado", "{Sum:$###,###,##0.00}");
            GridSummaryColumnDescriptor scd3 = new GridSummaryColumnDescriptor("Sum3", SummaryType.DoubleAggregate, "$GastoEnvio", "{Sum:$###,###,##0.00}");
            GridSummaryColumnDescriptor scd4 = new GridSummaryColumnDescriptor("Sum4", SummaryType.DoubleAggregate, "$Vta sin Envio y Sin IVA", "{Sum:$###,###,##0.00}");
            GridSummaryColumnDescriptor scd5 = new GridSummaryColumnDescriptor("Sum5", SummaryType.DoubleAggregate, "$Comision NORMAL", "{Sum:$###,###,##0.00}");
            GridSummaryColumnDescriptor scd6 = new GridSummaryColumnDescriptor("Sum6", SummaryType.DoubleAggregate, "$Comision 6MESES", "{Sum:$###,###,##0.00}");
            GridSummaryColumnDescriptor scd7 = new GridSummaryColumnDescriptor("Sum7", SummaryType.DoubleAggregate, "$Costo Publicidad", "{Sum:$###,###,##0.00}");
            GridSummaryColumnDescriptor scd8 = new GridSummaryColumnDescriptor("Sum8", SummaryType.DoubleAggregate, "$Costo Productos", "{Sum:$###,###,##0.00}");
            GridSummaryColumnDescriptor scd9 = new GridSummaryColumnDescriptor("Sum9", SummaryType.DoubleAggregate, "$Utilidad", "{Sum:$###,###,##0.00}");
            GridSummaryColumnDescriptor scd10 = new GridSummaryColumnDescriptor("Average1", SummaryType.DoubleAggregate, "%Utilidad Vs VentaSinIVA", "{Average:###0.00%}");
            GridSummaryColumnDescriptor scd11 = new GridSummaryColumnDescriptor("Average2", SummaryType.DoubleAggregate, "%Utilidad Vs Publicidad", "{Average:###0.00%}");
         //   dgReporte.TableDescriptor.SummaryRows["Totales: "].GetSummaryColumnAtCol(11).GetSummary(dgReporte,srd);
            srd.Name = "Totales: ";
            srd.SummaryColumns.AddRange(new GridSummaryColumnDescriptor[] { scd1, scd2, scd3, scd4, scd5, scd6, scd7, scd8, scd9, scd10, scd11 });
            
            //srd.Appearance.AnySummaryCell.Interior = new BrushInfo(Color.FromArgb(75, 75, 162));
            this.dgReporte.TableDescriptor.SummaryRows.Add(srd);
            this.dgReporte.ChildGroupOptions.ShowCaptionSummaryCells = true;
            this.dgReporte.ChildGroupOptions.ShowSummaries = false;
            this.dgReporte.ChildGroupOptions.CaptionSummaryRow = "Totales: ";
          //  this.dgReporte.ChildGroupOptions.CaptionText = "{RecordCount} Registros";            
            this.dgReporte.Appearance.GroupCaptionCell.BackColor = this.dgReporte.Appearance.RecordFieldCell.BackColor;
            this.dgReporte.Appearance.GroupCaptionCell.Borders.Top = new GridBorder(GridBorderStyle.Standard);
            this.dgReporte.Appearance.GroupCaptionCell.CellType = "Static";

            //Dando Fromato a la tabla

            GridConditionalFormatDescriptor format1 = new GridConditionalFormatDescriptor();     
            format1.Appearance.AnyRecordFieldCell.BackColor = Color.LimeGreen;
            format1.Expression = "[$Utilidad]  > 0";
            format1.Name = "ConditionalFormat 1";

            GridConditionalFormatDescriptor format2 = new GridConditionalFormatDescriptor();           
            format2.Appearance.AnyRecordFieldCell.BackColor = Color.Firebrick;
            format2.Expression = "[$Utilidad]  <= 0";
            format2.Name = "ConditionalFormat 2";
            
            this.dgReporte.TableDescriptor.ConditionalFormats.Add(format1);
            this.dgReporte.TableDescriptor.ConditionalFormats.Add(format2);

I really just need the value of [$Utilidad] when I group to format the Sumatory Row or the GroupRow, attach again the image to see the result


Error_5866418d.rar


AK Arun Kumar V Syncfusion Team February 5, 2013 04:15 AM UTC

Hi Serigo,

 The proposed solution will work. It seems you are using older version I have modified the sample to the older version. Please let me know the version you are using. So that we can provide the exact solution you are looking for. In our latest version we have modified the appearance of the grid using metro themes. A look of the grid in latest version with metro theme enabled. 

Please let me know if the issue still exits. We will help you as soon as possible.

Regards,

Arun.



New folder (14)_bd702050.zip

Loader.
Live Chat Icon For mobile
Up arrow icon