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

Changing BackColor of a Single Cell Based on Coordinates

I am using a GridGroupingControl and need to highlight a single cell based on it's coordinate. Specifically based on its column name and a particular primary key value on the row but I can get the coords if only I could figure out how to alter the style of only one cell. I've tried doing this a few different ways with no avail.
Currently I'm looping through the Records and when I find the correct one I am using the gridGroupingControl1.TableModel.SetCellInfo method but it doesn't seem to work. I cannot find any method or value on the Record object itself that will do this.

Is this possible? Any ideas?
I've Googled and not found anything usefull for my case.

7 Replies

CW Caleb Whitaker February 1, 2016 04:45 PM UTC

Now I am attempting to use the gridGroupingControl1.Table.GetTableCellStyle method to retrieve the cells style and then change its BackColor. Also not working thus far, nothing is changing.

CW Caleb Whitaker February 1, 2016 05:27 PM UTC

Another update:
I just tried using the QueryCellStyleInfo event. Not only did it not work, it dramatically slowed down my form so that's a no go as well.  

PK Pavithra Kodiyarasan Syncfusion Team February 2, 2016 11:40 AM UTC

Hi Caleb,

Thank you for your interest in Syncfusion products.

How to access the cell from co-ordinates

Please Find the below code snippet to get the row index and column index using co-ordinates.

//To calculate Row and column index of specified point

this.gridControl1.PointToRowCol(new Point(100, 100),out a,out b);

Cell based formatting using QueryCellInfo

To dynamically set the style properties on a cell, the QueryCellStyleInfo event has to be handled. You can access the row of the cell and check whether it is a RecordRow or not. Assuming the datasource as a DataTable, the GridRecordRow.Record.GetData method returns the data as a DataRowView object. Then by using the DataRowView, you can access the data in the row and after checking the conditions, change the style of the row. Refer to the following code example.

this.gridGroupingControl1.QueryCellStyleInfo += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventHandler(this.gridGroupingControl1_QueryCellStyleInfo);

private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)


    //Disables the row when the value of Name in the same row is Row1.

    if (e.TableCellIdentity.RowIndex != -1)


     GridRecordRow rec =  this.gridGroupingControl1.Table.DisplayElements[e.TableCellIdentity.RowIndex]as GridRecordRow;       

     if (rec != null)


            // Applies format by checking the value ‘Row1’

            DataRowView dr = rec.GetData() as DataRowView;

            if (dr != null && dr["Name"].Equals("Row1"))


                e.Style.Enabled = false;

                e.Style.BackColor = Color.Azure;







Conditional formatting

To conditionally set the style of a row in the GridGroupingControl, you can apply the row styles by using the Conditional Formatting function. You can refer to the following code example to apply Conditional Formatting to the records that have the cell value of Row1.


// Event triggering from designer

//Creates FormatDescriptor

Syncfusion.Windows.Forms.Grid.Grouping.GridConditionalFormatDescriptor gridConditionalFormatDescriptor3 = new Syncfusion.Windows.Forms.Grid.Grouping.GridConditionalFormatDescriptor(); 

//Conditional Formatting applied through designer

gridConditionalFormatDescriptor3.Appearance.AnyRecordFieldCell.Interior = new Syncfusion.Drawing.BrushInfo(System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(191)))), ((int)(((byte)(52))))));

gridConditionalFormatDescriptor3.Appearance.AnyRecordFieldCell.TextColor = System.Drawing.Color.White;

gridConditionalFormatDescriptor3.Appearance.AnyRecordFieldCell.Enabled = false;

// Applies format by checking the value ‘Row1’

gridConditionalFormatDescriptor3.Expression = "[Name]  LIKE \'Row1\'";

gridConditionalFormatDescriptor3.Name = "ConditionalFormat 1";

//Adds conditional format descriptor to the GridGroupingControl TableDescriptor. this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(gridConditionalFormatDescriptor3);


Pavithra K.

CW Caleb Whitaker February 2, 2016 04:27 PM UTC

The QueryCellStyleInfo Event worked for what I needed. Just added in a condition checking the column index so it only colored that single cell rather than the whole row.


CW Caleb Whitaker February 2, 2016 06:55 PM UTC

Actaully I have a follow up question.
The QueryCellStyleInfo Event happens so many times that even a little complexity lags the form...
I'm gonig to keep hacking to see if I can get it running efficiently.
But I cannot use the Conditional Formatting way to select a single cell rather than a row correct?

CW Caleb Whitaker February 2, 2016 08:20 PM UTC

I've got it working ok now. Only a slight delay is all.

SA Solai A L Syncfusion Team February 3, 2016 06:46 AM UTC

Hi Caleb,

Thank you for your update. We are glad to know that your issue has been solved.

The QueryCellStyleInfo event is used to dynamically set the style properties on a cell of a grid. So, it gets triggered repeatedly. And this GridConditionalFormatDescriptor can be used for applying formatting only based on records.


Live Chat Icon For mobile
Up arrow icon