Set a backColor of cell based on another cell value

Hi everyone, 

I have a Sfdatagrid already filled and I need to set a backcolor of a cell of column "D" based on a cell value of column "A", but I cannot find a way to do it.

Does anyone have any suggestions?

Thanks in advance

Tullio




1 Reply

SB Sweatha Bharathi Syncfusion Team November 6, 2023 02:31 PM UTC

Hi Tullio ,


We have analyzed your query, Your requirement can be achieved by using the QueryCellStyle event. We have provided a code snippet and sample for your reference. Kindly review the sample and let us know if you have any concerns on this .



Code Snippet :


private void SfDataGrid_QueryCellStyle(object sender, QueryCellStyleEventArgs e)

 {

 

     if (e.Column.MappingName == "CustomerName")

     {

             if ((e.DataRow.RowData as OrderInfo).SalaryCredited)

                 e.Style.BackColor = Color.Green;

             else

                 e.Style.BackColor = Color.Red;

 

     }

 }


Image Reference:


 




Attachment: Sample_27f2747e.zip

Loader.
Up arrow icon