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

How can I change the background color of a cell after editing the value

I know that you can use conditional formatting to change the background color but that is based on a criteria. I went to be able to change the background color of a cell after the value has changed so I can visually see all cells that were modified within the PivotGrid. This is in the Winforms version of the control.

2 Replies

GB George Busby July 14, 2019 12:19 AM UTC

I was able to find a way to change the color of the background when a cell is edited.  here is the code I created, is this the correct way to do it?

 Dim CellStyle As New Syncfusion.Windows.Forms.Grid.GridStyleInfo
 Me.PivotGridControl1.TableModel.GetCellInfo(Me.PivotGridControl1.TableControl.CurrentCell.RowIndex, Me.PivotGridControl1.TableControl.CurrentCell.ColIndex, CellStyle)
 CellStyle.BackColor = Color.AliceBlue
 Dim MyType As Syncfusion.Styles.StyleModifyType
 MyType = Syncfusion.Styles.StyleModifyType.Changes
 Me.PivotGridControl1.TableModel.SetCellInfo(Me.PivotGridControl1.TableControl.CurrentCell.RowIndex, Me.PivotGridControl1.TableControl.CurrentCell.ColIndex, CellStyle, MyType)

TB Thirupathi Bala Krishnan Syncfusion Team July 15, 2019 01:46 PM UTC

Hi George,

We have analyzed the reported query – “How to change the background color value for the edited cell”. You can achieve this requirement by defining the back color and font styles inside the PrepareViewStyleInfo event handler. You can find out the row and column index values of edited cell by using the CurrentCell property.

Please refer the following code sample.

Imports Syncfusion.Windows.Forms.Grid 
Imports System.Drawing 
Private isEditingCompleted As Boolean

        Public Sub New() 
            AddHandler pivotGridControl1.TableControl.CurrentCellStartEditing, AddressOf Me.TableControl_CurrentCellStartEditing 
            AddHandler pivotGridControl1.TableControl.CurrentCellEditingComplete, AddressOf Me.TableControl_CurrentCellEditingComplete 
            AddHandler pivotGridControl1.TableControl.PrepareViewStyleInfo, AddressOf Me.TableControl_PrepareViewStyleInfo 
        End Sub

        Private Sub TableControl_CurrentCellEditingComplete(ByVal sender As Object, ByVal e As EventArgs) 
            isEditingCompleted = True 
        End Sub 
        Private Sub TableControl_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs) 
            If isEditingCompleted AndAlso e.ColIndex = pivotGridControl1.TableControl.CurrentCell.ColIndex - 1 AndAlso e.RowIndex = pivotGridControl1.TableControl.CurrentCell.RowIndex Then 
                e.Style.BackColor = Color.Orange 
                e.Style.Font.Bold = True 
                e.Style.Font.Italic = True 
                isEditingCompleted = False 
            End If 
        End Sub 
Before editing the cell value, 

After editing the cell value,

Please let us know if you need any further assistance.

Thirupathi B.


Live Chat Icon For mobile
Up arrow icon