Cell format based on other cell values in the same row

Hi,

In the examples can see lots of way to format cells by column name but are looking to format a cell based on other cell values in the same row. E.g.

                if (e.CellElement.ColumnInfo.HeaderText == Sectional20)
                {
                    if (e.CellElement.RowInfo.Cells[Sectional20FrontRear].Value != null)
                    {
                        if ((string)e.CellElement.RowInfo.Cells[Sectional20FrontRear].Value == "Rear")
                        {
                            e.CellElement.ForeColor = Color.FromArgb(201, 0, 30);
                            e.CellElement.Font = newFontBold;
                        }
                        else if ((string)e.CellElement.RowInfo.Cells[Sectional20FrontRear].Value == "Front")
                        {
                            e.CellElement.ForeColor = Color.FromArgb(44, 100, 170);
                            e.CellElement.Font = newFontBold;
                        }
                        else
                        {
                            e.CellElement.ForeColor = Color.FromArgb(0, 0, 0);
                            e.CellElement.Font = newFontRegular;
                        }
                    }
                }

Is this possible with Syncfusion sfDataGrid.

Kind regards,

Neil

2 Replies 1 reply marked as answer

NE Neil February 11, 2021 06:15 PM UTC

Resolved. I used the datarowview to get the rowdata.

            if (e.Column.MappingName == "Sectional20")
            {
                DataRowView dv = (DataRowView)e.DataRow.RowData;

                if (dv.Row["Sectional20FrontRear"] != null)
                {
                    if (dv.Row["Sectional20FrontRear"].ToString() == "Rear")
                    {
                        e.Style.BackColor = Color.LightBlue;
                    }
                    else if (dv.Row["Sectional20FrontRear"].ToString() == "Front")
                    {
                        e.Style.BackColor = Color.RosyBrown;
                    }
                    else
                    {
                        e.Style.BackColor = Color.Black;
                    }
                }
            }

Marked as answer

MA Mohanram Anbukkarasu Syncfusion Team February 12, 2021 10:42 AM UTC

Hi Neil, 

Thanks for the update. 

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 

Regards, 
Mohanram A. 


Loader.
Up arrow icon