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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:





145920 Jul 13,2019 12:02 PM UTC Jul 15,2019 01:46 PM UTC WinForms 2
Tags: PivotGridControl
George Busby
Asked On July 13, 2019 12:02 PM UTC

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.

George Busby
Replied On 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)

Thirupathi Bala Krishnan [Syncfusion]
Replied On 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.



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

Live Chat Icon For mobile
Live Chat Icon