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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Alternating Column background colors in pivotgrid

Thread ID:





130801 Jun 3,2017 07:40 PM UTC Jul 31,2017 04:55 AM UTC WinForms 3
Tags: PivotGridControl
Jens Christensen
Asked On June 3, 2017 07:40 PM UTC

I'm trying to change the back colors of the columns to be alternating, but I cannot figure out how.

        Me.PivotGridControl1.ItemSource = ProductSales.GetSalesData()

        ' Adding Pivot Rows to Grid
        Me.PivotGridControl1.PivotRows.Add(New PivotItem With {.FieldMappingName = "Product", .TotalHeader = "Total"})
        Me.PivotGridControl1.PivotRows.Add(New PivotItem With {.FieldMappingName = "Date", .TotalHeader = "Total"})

        ' Adding Pivot Columns to Grid           
        Me.PivotGridControl1.PivotColumns.Add(New PivotItem With {.FieldMappingName = "Country", .TotalHeader = "Total"})
        Me.PivotGridControl1.PivotColumns.Add(New PivotItem With {.FieldMappingName = "State", .TotalHeader = "Total"})

        ' Adding Pivot Calculations to Grid          
        Me.PivotGridControl1.PivotCalculations.Add(New PivotComputationInfo With {.FieldName = "Amount", .Format = "C", .SummaryType = SummaryType.DoubleTotalSum})
        Me.PivotGridControl1.PivotCalculations.Add(New PivotComputationInfo With {.FieldName = "Quantity", .Format = "#,##0"})

So, I would like, for example, the "Amount" column to be light Gray and the "Quantity" column to be dark gray.

Anyone can enlighten me?


Arulpriya Ramalingam [Syncfusion]
Replied On June 5, 2017 12:55 PM UTC

Hi Jens, 

Thanks for your interest in Syncfusion products. 

In order to change the background color for alternate columns, the QueryCellInfo event can be used. In that event, BackColor property can be used to set the back color for the alternate columns. Please make use of below code and sample, 

Code snippet 
'Event Subscription 
AddHandler Me.pivotGridControl1.TableModel.QueryCellInfo, AddressOf TableModel_QueryCellInfo 
'Event Customization 
Private Sub TableModel_QueryCellInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs) 
    If e.RowIndex > 0 AndAlso e.ColIndex > 0 Then 
         If e.ColIndex Mod 2 = 0 Then 
            e.Style.BackColor = Color.LightBlue 
             e.Style.BackColor = Color.LightGreen 
       End If 
    End If 
End Sub 


Jens Christensen
Replied On July 28, 2017 08:44 AM UTC

Sorry, forgot to reply earlier, this worked perfectly, thank you very much

Arulpriya Ramalingam [Syncfusion]
Replied On July 31, 2017 04:55 AM UTC

Hi Jens,    
We are glad to hear that the provided solution was resolved your scenario.   
Please let us know if you need further assistance.    


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon