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

Changing cell background color

Thread ID:





141002 Nov 18,2018 09:47 PM UTC Nov 19,2018 09:16 AM UTC WinForms 1
Tags: SfDataGrid
Asked On November 18, 2018 09:47 PM UTC

Hi, is is possible to set a cell background color without using QueryCellStyle

Something like SetCellBackgroundColor(column,row)


Deivaselvan Y [Syncfusion]
Replied On November 19, 2018 09:16 AM UTC

Hi Chris, 
Thanks for contacting Syncfusion support. 
SfDataGrid is designed based on column-oriented architecture and it is not a cell-based grid. It is impossible to change the back color of any specific cell in SfDataGrid without using QueryCellStyle event.  
However, you can achieve your requirement to set background color of a cell using method like SetCellBackgroundColor. It can be achieved by maintaining a Dictionary with RowcolumnIndex of the cell as Key and the background color as value. Based on the value in the dictionary set the background color of the cell within the QueryCellStyle event. Please refer to the following code example and sample from the given location to change the background color of a specific cell in a button click event. 
Code example :  
Dictionary<RowColumnIndex, Color> colorDict = new Dictionary<RowColumnIndex, Color>(); 
void SetCellBackgroundColor(RowColumnIndex rowColumnIndex, Color color) 
    if (!colorDict.ContainsKey(rowColumnIndex)) 
        colorDict.Add(rowColumnIndex, color); 
        colorDict[rowColumnIndex] = color; 
    sfDataGrid.TableControl.Invalidate(this.sfDataGrid.TableControl.GetCellRectangle(rowColumnIndex.RowIndex, rowColumnIndex.ColumnIndex, false)); 
this.sfDataGrid.QueryCellStyle += sfDataGrid_QueryCellStyle; 
void sfDataGrid_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e) 
    var rowColumnIndex = new RowColumnIndex(e.RowIndex,e.ColumnIndex); 
    if (colorDict.ContainsKey(rowColumnIndex)) 
        e.Style.BackColor = colorDict[rowColumnIndex]; 
private void button1_Click(object sender, System.EventArgs e) 
    SetCellBackgroundColor(new RowColumnIndex(1, 0), Color.LightBlue); 


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