We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

What is the best way to refresh sfDataGrid UI?

From a performance point of view - what is the best way to refresh a grid on the display?

I have en app where the user can select different skins and the skinning of the datagrid is implemented on both grid and cell levels:

grid (for headers and gridlines):

GridStyle="{StaticResource gridColors}"


    <Style TargetType="syncfusion:GridCell">
        <Setter Property="Foreground"
            Value="{Binding UserData[0].TextColor, Mode=OneWay}" />
        <Setter Property="BackgroundColor"
            Value="{Binding UserData[0].BackgroundColor, Mode=OneWay}" />

All of this works exactly as I want it to, no problem. But when a user select a new skin, I need to initiate a refresh of the complete grid to apply the new skin, and the only way I have found to do this is through:

dataGrid.ItemsSource = null;
dataGrid.ItemsSource = data.Items;

This also do exactly what I want it to do, but the performance is rather poor.  Is there any better way to initiate a refresh of the grid style? (The content of the grid is unchanged, only the style is changed)

3 Replies

AN Ashok N Syncfusion Team October 6, 2017 12:56 PM UTC

Hi Gunnar, 
Thanks for contacting Syncfusion support. 
We have checked your query and you can refresh the view by using DataRowBase.UpdateRow methods. Please refer the below code example  
private void Button_Clicked(object sender, EventArgs e) 
    var items = dataGrid.GetRowGenerator().Items; 
    foreach (var item in items) 

GC Gunnar Carlson October 6, 2017 10:21 PM UTC

I tried the method you suggested and it doesn't do anything visible. Maybe the UpdateRow method tries to update the data content on the row, but since the content isn't changed, no visible change is made when the method is called. The only things that should be updated is the styling, and I can't see that UpdateRow do that.

BUT...I have found a solution through a tip you gave in one of my other questions.

Since a row in my case is an array of the class UserData, all I had to do was to raise a PropertyChanged event for "UserData"

foreach (var item in data.Items)
dataGrid.GridStyle = new GridColors();

The last line is to trigger an update of GridStyle (I have a gridstyle class defining some of the colors.)

With those two additions, I can make the datagrid apply the new skin much faster than when i re-bound the ItemSource. Problem solved.

VP Vimal Prabhu Manohkaran Syncfusion Team October 9, 2017 11:35 AM UTC

Hi Gunnar,

Thanks for the update. Since you are using CellStyles for the GridCell, the approach you have mentioned above is the recommended and efficient approach. So we recommend you to stick on to the same.

Vimal Prabhu

Live Chat Icon For mobile
Up arrow icon