This is a migrated thread and some comments may be shown as answers.

How to refresh bound grid to show new record?

5 Answers 169 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jingying
Top achievements
Rank 1
Jingying asked on 03 Jun 2009, 01:37 AM
i have my Datagrid bound to a global collection.
When i add new record to the global collection, how do i get the datagrid to refresh so that the new record shows up in the data grid?

5 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Top achievements
Rank 1
answered on 03 Jun 2009, 03:36 AM
If your collection is INotifyCollectionChanged the grid will show new record automatically - in all other situations you can call Rebind() method.
0
Marc Roussel
Top achievements
Rank 2
answered on 05 May 2010, 02:52 PM
Also be careful when you have filters applied to your collection as this could result in a refresh not working if you just issue a Rebind.  Make sure you re apply any filter you added and if this means you don't need the rebind then don't use the rebind but your own filter instead.

0
Sajan
Top achievements
Rank 1
answered on 05 Sep 2012, 11:37 AM
Hi Vlad,
i have implemented notify property changed. it brings all the new records immediately but it does not show the updated value of record.
0
Pavel Pavlov
Telerik team
answered on 06 Sep 2012, 12:49 PM
Hello,

The approach would be similar :

In your Record objects , you should implement the INotifyPropertyChanged interface.

Generally RadGridView would respect both: INotifyCollectionChanged and INotifyPropertyChanged interfaces.
If you have them correctly implemented any updates would be reflected automatically at the UI with no need of you to take care of it.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sajan
Top achievements
Rank 1
answered on 06 Sep 2012, 03:32 PM
Hi Pavel Pavlov,
I have implemented it like this. Can you please check if i am missing something.
public class SalesOrderViewModel : INotifyPropertyChanged
  {
      //Supplies the collection of Products that the Mainpage.ProductList binds to
      public ObservableCollection<SalesOrder> Orders { get; set; }
 
      private SalesOrder _selectedOrder;
 
      public SalesOrder SelectedOrder
      {
          get { return _selectedOrder; }
          set
          {
              _selectedOrder = value;
              NotifyPropertyChanged("SelectedOrder");
 
          }
      }
      public event PropertyChangedEventHandler PropertyChanged;
      /// <summary>
      /// NotifyPropertyChanged will raise the PropertyChanged event passing the
      /// source property's name that is being updated.
      /// </summary>
      /// <param name="propertyName"></param>
      public void NotifyPropertyChanged(String propertyName)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
 
      public SalesOrderViewModel()
      {
          Orders = new ObservableCollection<SalesOrder>();
          SelectedOrder = null;
      }
  }

It will be a great help.
 Regards
Sajan
Tags
GridView
Asked by
Jingying
Top achievements
Rank 1
Answers by
Vlad
Top achievements
Rank 1
Marc Roussel
Top achievements
Rank 2
Sajan
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or