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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to refresh sfDataGrid items

Thread ID:





118940 Apr 26,2015 11:09 PM UTC Apr 29,2015 07:05 AM UTC WPF 5
Tags: SfDataGrid
Biju Vargheese
Asked On April 26, 2015 11:09 PM UTC

In my WPF app, I have a simple sfdatagrid that I bind to "EditedForms" collection as shown below.
        <syncfusion:SfDataGrid x:Name="gridSaved" Margin="452,10,10,0" VerticalAlignment="Top" Height="405"
                ItemsSource="{Binding EditedForms}">
                <syncfusion:GridTextColumn HeaderText="Form" MappingName="Name" />
When I delete a file from the folder, I update the "EditedForms" collection. 
        public void RefreshSavedFolder() {
            DirectoryInfo dInfo = new DirectoryInfo(SavedPath);
            foreach (FileInfo file in dInfo.GetFiles()) {
                EditedForms.Add(new FormTemplate(file.Namefile.DirectoryNamefile.FullName));
How do I refresh this grid with the new collection on button click event?


Gobikrishnan Murugesan [Syncfusion]
Replied On April 27, 2015 08:34 AM UTC

Hi Biju Vargheese,

Thank you for using Syncfusion products.

We have analyzed your query. Based on your code snippet, we are unable to find the collection type you are using whether it is List, ObservableCollection. If you are using ObservableCollection which implements INotifyCollectionChanged interface, SfDataGrid will be refreshed for Add and Remove operations in collection. If you are using List collection which does not implement the INotifyCollectionChanged interface, you can manually refresh the using below code snippet (using SfDataGrid.View.BeginInit() , SfDataGrid.View.EndInit() and SfDataGrid.View.Refresh() methods)

Code Snippet for Refresh the View if you are using List:

//When BeginInit method is called it suspends all the updates until EndInit method is called



viewmodel.Products.Add(new Product("P1", "HardWare", 1, "Jon"));

viewmodel.Products.Add(new Product("P2", "Software", 2, "Jhon"));

viewmodel.Products.Add(new Product("P3", "HardWare", 3, "Michel"));



Please let us know if you have any other queries.


Gobikrishnan M

Biju Vargheese
Replied On April 27, 2015 03:21 PM UTC

Hi Gopi,
Thanks for your fast response! I am using a collection of FormTemplate objects.  FormTemplate is a simple class with two properties: Name and Category.
public ObservableCollection<FormTemplate> EditedForms { getprivate set; }
My code adds a new item to the collection. But I was expecting the grid to auto-refresh and display it. I might be missing something... Any idea?
            foreach (FileInfo file in dInfo.GetFiles()) {
                EditedForms.Add(new FormTemplate(file.Name"Saved"file.DirectoryName));

Gobikrishnan Murugesan [Syncfusion]
Replied On April 28, 2015 01:37 PM UTC

Hi Biju,

We have analyzed your query. As mentioned in our previous update, in Observable collection, the collection itself implements the INotifyCollectionChanged interface. So SfDataGrid will be refreshed automatically for Add, Remove and Clear operations in collection. Based on your code snippet, we have prepared a sample and it can be downloaded from the following location.


In this sample, we have performed the operations like clearing the items and add new items in collection as you updated, but our SfDataGrid refreshed automatically. Could you please update more information on reported problem like modifying the above sample or provide issue reproducing sample to us? It would be better for us and provide a better solution.

Please let us know if you require further assistance on this.


Gobikrishnan M

Biju Vargheese
Replied On April 28, 2015 03:49 PM UTC

Thanks Gobi,
That was helpful. My code was directly modifying the collection instead of getting it from the grid.DataContext.

            var formUser = (FormUsergridSaved.DataContext;

Gobikrishnan Murugesan [Syncfusion]
Replied On April 29, 2015 07:05 AM UTC

Hi Biju,

Thanks for the update.
Please let us know if you require any further assistance on this.

Gobikrishnan M


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon