How to generate and assign row style by the code behind?

Hi

I have a reequipment that is 

generate a new color style from c# and assign to Specify row index to SFDatagrid.



1 Reply

MA Mohanram Anbukkarasu Syncfusion Team November 12, 2021 02:27 PM UTC

Hi Johnes, 

Thanks for contacting Syncfusion support.  

We would like to let you know that you can achieve your requirement by using CellStyleSelecto. We have prepared a sample to replicate this scenario and it is available in the following link for your reference.  

Code example :  

public partial class MainWindow : Window 
{ 
    public MainWindow() 
    { 
        InitializeComponent(); 
 
        this.dataGrid.CellStyleSelector = new CustomRowStyleSelector(); 
    } 
} 
 
 
public class CustomRowStyleSelector : StyleSelector 
{ 
    public override Style SelectStyle(object item, DependencyObject container) 
    { 
        if((container as GridCell).ColumnBase.RowIndex == 2) 
        { 
            Style style = new Style(typeof(GridCell)); 
 
            style.Setters.Add(new Setter(GridCell.BackgroundProperty, Brushes.Green)); 
 
            return style; 
        } 
 
        return base.SelectStyle(item, container); 
    } 
} 



Please have a look at this sample and let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 




Loader.
Up arrow icon