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

Alternating Column background colors in pivotgrid

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?


3 Replies

AR Arulpriya Ramalingam Syncfusion Team 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 


JC Jens Christensen July 28, 2017 08:44 AM UTC

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

AR Arulpriya Ramalingam Syncfusion Team 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.    

Live Chat Icon For mobile
Up arrow icon