How to change background color of Row Header based on value in another Column

Hello,

I am using sfDataGrid for Winforms, and am struggling to get the row header to color based on the value of another cell in that row. In my example I want all values with True to color the row header green, and False to color Red. Any help or a point in the right direction would be appreciated.

Thanks,
Chuck



Row HeaderValue

                     
True

                     
False



1 Reply

FP Farjana Parveen Ayubb Syncfusion Team May 18, 2018 05:56 AM UTC

Hi Chuck, 

Thanks for contacting Syncfusion support. 

We can able to change the back color of the RowHeader based on the other column value by using DrawCell event in SfDataGrid. Please refer the below code example and sample in the following location, 

Code Example: 

sfDataGrid.ShowRowHeader = true; 
sfDataGrid.DrawCell += SfDataGrid_DrawCell; 
 
 
private void SfDataGrid_DrawCell(object sender, Syncfusion.WinForms.DataGrid.Events.DrawCellEventArgs e) 
{ 
    if (sfDataGrid.ShowRowHeader && e.RowIndex != 0) 
    { 
        var cellValue = (e.DataRow.RowData as OrderInfo).IsDisposed; 
        if (e.ColumnIndex == 0) 
            e.Style.BackColor = cellValue == true ? System.Drawing.Color.Green : System.Drawing.Color.Red; 
    } 
} 

 
Regards, 
Farjana Parveen A 


Loader.
Up arrow icon