Dynamic change of cell background ?

I have a grid populated via a list of objects with properties (i.e. List<myRowObject>). After the display, the user may run another process to cross control the data displayed on this grid and if that process identifies a specific row or cell to be relevant, I want to be able to change the background color of that cell or row without reloading the data. Is this possible ? Thank you.

1 Reply 1 reply marked as answer

KK Karthikraja Kalaimani Syncfusion Team December 21, 2020 12:33 PM UTC

Hi Halil,

By using the reflection way we can set the row background color without loading a new data, but if we scroll up and down the original cell background color will applied to the row. Please refer to the below code snippet and attached sample.
 
 
Code snippet :

 
  <Button Text="Click To Change Color" Clicked="Button_Clicked"></Button> 
            <sfgrid:SfDataGrid x:Name="mainDataGrid" 
                         Grid.Row="1" 
                         AutoGenerateColumns="False" 
                         ColumnSizer="Star" 
                         ItemsSource="{Binding OrdersInfo}"   
                         > 
                <sfgrid:SfDataGrid.Columns> 
                    <sfgrid:GridTextColumn HeaderText="Column 2" Width="100" MappingName="OrderID"></sfgrid:GridTextColumn> 
                    <sfgrid:GridTextColumn Width="200"  MappingName="EmployeeID"></sfgrid:GridTextColumn> 
                    <sfgrid:GridTemplateColumn  Width="50" MappingName="EmployeeID"> 
                        <sfgrid:GridTemplateColumn.CellTemplate> 
                            <DataTemplate> 
                                <Label Text="{Binding EmployeeID}" FontFamily="fontawesome-webfont"> 
                                </Label> 
                            </DataTemplate> 
                        </sfgrid:GridTemplateColumn.CellTemplate> 
                    </sfgrid:GridTemplateColumn> 
                </sfgrid:SfDataGrid.Columns> 
            </sfgrid:SfDataGrid>


DataRowBase rowdata; 
 
        VirtualizingCellsControl wholeRowElement; 
        public MainPage() 
        { 
            InitializeComponent(); 
             
        } 
 
        private void Button_Clicked(object sender, EventArgs e) 
        { 
            var model = (GridModel)mainDataGrid.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name.Equals("GridModel")).GetValue(mainDataGrid); 
            rowdata = SfDataGridHelpers.GetRowGenerator(mainDataGrid).Items.FirstOrDefault(x => x.RowIndex == 2); 
            if (rowdata != null) 
            { 
                wholeRowElement = (VirtualizingCellsControl)rowdata.GetType().GetRuntimeFields().FirstOrDefault(x => x.Name.Equals("WholeRowElement")).GetValue(rowdata); 
                wholeRowElement.BackgroundColor = Xamarin.Forms.Color.Red; 
            } 
        } 

Regards,
Karthik Raja
 


Marked as answer
Loader.
Up arrow icon