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

How to refresh or requery the radgridview?

11 Answers 896 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 02 Jul 2010, 10:09 PM
Hi,

             Scenario:
                          RIA is used to populate the grid. First time you load the xaml page. It will execute the code and load the data to the RADGridView. It's working fine.

               Problem:
                           How can I control on my code to requery and refresh the grid? Just like if I put a button on the page and label it as REFRESH. This should grab the data from the database and repopulate the grid.


                Please help...


Thanks,
Chris

11 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 05 Jul 2010, 07:03 AM
Hello Chris,

How about calling the Load() method of the DomainDataSource? It should reload the data from the server.

Regards,
Veskoni
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Malcolm
Top achievements
Rank 1
answered on 26 Sep 2010, 02:19 PM
Using a Domain Datasource I found I needed to call Clear() on the Datasource first, otherwise the data is stale

this.DomainDataSource1.Clear();
this.DomainDataSource1.Load();

0
Dean Wyant
Top achievements
Rank 1
answered on 07 Mar 2011, 08:17 PM
I thought this issue was exactly what I was looking for.
Load does cause the data to be re-read from the WCF RIA. However, the grid does not actually display the new data.
A RadDomainDataSource does not have a Clear() method.

I am using a LinqToSqlDomainService and I need to cause the RadGridView to refresh without losing selections, etc.
The data is changed by other apps, so property changed events seem unrelated.

Let me make up an example:
My silverlight app shows a grid that is filled with stock portfolio information from a Entity that was generated using WCF RIA Domain Service (LinqToSQL).
e.g.

 

 

StockDS ctx = new StockDS();

 

 

_DS =

 

new RadDomainDataSource();

 

 

_DS.Name =

 

"DS";

 

 

_DS.PageSize = 10;

 

_DS.AutoLoad =

 

true;

 

 

_DS.DomainContext = ctx;

 

_DS.QueryName =

 

"GetStock_StatsQuery";

 

 

_grid.IsReadOnly =

 

true;

 

 

_grid.DataContext = _DS;

 

_grid.ItemsSource = ctx.Stock_Stats;


The table on the server is updated from other unknown applications. I have set a timer to call a Refresh method every 60 seconds.

 

 

protected override void OnRefresh()

 

 

{

 

 

 

  if (_DS != null)

 

 

  {

 

    _DS.Load();

  }

}

This Load call does cause the service's GetStock_StatsQuery to be called and the Entity to reload.
However... Even though the data has changed, the grid continues to show the original data. It does not update.

How do I cause the grid to redraw using the new data?

Thanks.


0
Yavor Georgiev
Telerik team
answered on 10 Mar 2011, 03:58 PM
Hello Dean Wyant,

 Could you please try binding the ItemsSource of RadGridView to the DataView property of RadDomainDataSource, like so:
_grid.SetBinding(RadGridView.ItemsSourceProperty, new Binding("DataView"));

Alternatively, the Stock_Stats property of your StockDS class has to raise PropertyChanged whenever you assign a new value to it.

All the best,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Dean Wyant
Top achievements
Rank 1
answered on 10 Mar 2011, 04:43 PM
Sorry, binding to "DataView" did not help.

The StockDS is an auto generated DomainContext generated by the WCF RIA code.
The Entity type is autogenerated also.
They are generated from LinqToSql classes in the WebSite app.

A "Domain Sevice Class" is added to a web site by choosing the tables from the Linq2ToSQL. The SL app gets a Generated_Code\Website.g.cs generated for service access.
I cannot change the code in Website.g.cs.
The Entity class does call RaiseDataMemberChanging and RaiseDataMemberChanged when properties are changed.
This particular table has only read code (no edits or deletes) if that makes a difference.
They are partial classes, so I guess code could be added in another cs file to extend the classes.

I just want to call code to refresh the data in the grid without losing selection, scroll position, etc.

The context Load command does cause the Entity collection to reload, but the grid does not update its display.
I understand that it is not updating because a property changed notification is not being received. I need some code to cause a property change notification or anything else that will cause a redisplay of the currently visible data.

I also have tried reassigning ItemsSource (= null, then back again). It did not work.

I believe that this is a very popular method of data access for SL apps.
I think I am using a normal, popular method of binding... nothing "special". 
So, I would think that this should be a question easily answered.
I am not sure why I seem to always be running into things that I think will be easy but turn out to be complex.



0
Yavor Georgiev
Telerik team
answered on 11 Mar 2011, 11:50 AM
Hello Dean,

 From what I can tell from the code you've posted, the problem is that you're setting the ItemsSource of your RadGridView to a property of your DomainContext (StockDS), whereas it should be set to the DataView of your DomainDataSource.

 Either try specifying the binding source manually:
_grid.SetBinding(RadGridView.ItemsSourceProperty, new Binding("DataView") { Source = _DS });
 or set the property manually:
_grid.ItemsSource = _DS.DataView;

 If both fail, could you please open a separate support ticket and attach your application there so that I can get a better look at your scenario and approach?

Regards,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Dean Wyant
Top achievements
Rank 1
answered on 11 Mar 2011, 05:16 PM
I tracked this down to the client DomainContext caching the Entity.
The default LoadBehaviour is not RefreshCurrent. So, calling Load() retrieves the new data, but the grid is bound to the cached data which does not change (due to default LoadBehaviour).

To fix this, the LoadBehavior needs to be set to RefreshCurrent.
That can be done within the LoadingData event:
 
protected override void OnRefresh()
{
  RadDomainDataSource _DS = _grid.DataContext as RadDomainDataSource;
  if (_DS != null)
  {
    _DS.LoadingData += new EventHandler<Telerik.Windows.Controls.DomainServices.LoadingDataEventArgs>(_DS_LoadingData);
    _DS.Load();
  }
}
void _DS_LoadingData(object sender, Telerik.Windows.Controls.DomainServices.LoadingDataEventArgs e)
{
  e.LoadBehavior = LoadBehavior.RefreshCurrent;
}

Or, if you do not mind hard coding the query, you can do it without handling an event:

 

protected override void OnRefresh()
{
  RadDomainDataSource _DS = _grid.DataContext as RadDomainDataSource;
  if (_DS != null)
  {
    ((StockDS)_DS.DomainContext).Load(((StockDS)_DS.DomainContext).GetStock_StatsQuery(), LoadBehavior.RefreshCurrent, null, null);
  }
}

I did not see a direct way to set the LoadBehavior before calling the DataSource.Load() so LoadingData had to be handled.

It seems very strange that the default setting does not refresh the current data. If it did, then this problem would not exist... perhaps then, other people would be wondering why a Load() is overwriting their changes?? It seems unlikely.

I do not know why it is so difficult to find this solution. It should be in the top ten tips for using Domain Data Source (WCF RIA). Or, in a list of pitfalls.

Q. How do I refresh the data to reflect changes made by other applications?
A. You will need to get the context LoadBeviour set to RefreshCurrent. See above code examples.

Like they say...  it is like pulling teeth! Totally rediculous.




0
Yavor Georgiev
Telerik team
answered on 11 Mar 2011, 05:58 PM
Hi Dean,

 Thank you for noting this for us. We will make sure to include it in the RadDomainDataSource help files immediately. I have awarded you telerik points.

Greetings,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Sajan
Top achievements
Rank 1
answered on 05 Sep 2012, 11:17 AM
Hi,
 I have used the observable collection and used a linq query to dataservice of crm 2011.like
DataServiceQuery<SalesOrder> query = result.AsyncState as DataServiceQuery<SalesOrder>;
TheSalesOrderViewModel.Orders = new DataServiceCollection<SalesOrder>(query.EndExecute(result));
TheSalesOrderViewModel.NotifyPropertyChanged("Orders");
this.RadGrid.DataContext = TheSalesOrderViewModel;
this.RadGrid.ItemSource= TheSalesOrderViewModel.Orders;
when i am re-quering after changing the status of Selected sales order.i am not able to retrieve the changed status of record. Although it displays the new record created in CRM immediately after re-querying the data,on the RadGrid.(i.e. calling the same lines of code as above).
Can You Please Tell me how can i display the Updated information(i.e. order status change )on the Radgrid Without refreshing the whole page ?
Please help Me Asap.

Regards
Sajan 


  
0
Pavel Pavlov
Telerik team
answered on 06 Sep 2012, 12:58 PM
Hi Sajan,

Doesn't the RadGridView.Rebind() method do the trick ? 

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:46 PM
Hi Pavel Pavlov,
Thanks for your quick reply. But Rebind() didnot work.
Is there any workaround to achieve this? Here is the sample code.
DataServiceQuery<SalesOrder> query = result.AsyncState as DataServiceQuery<SalesOrder>;
               TheSalesOrderViewModel.Orders = new DataServiceCollection<SalesOrder>(query.EndExecute(result));
                         
               TheSalesOrderViewModel.NotifyPropertyChanged("SelectedOrder");
               this.RadGrid.Rebind();
               this.RadGrid.DataContext = TheSalesOrderViewModel;
               this.RadGrid.ItemsSource = TheSalesOrderViewModel.Orders;

Can you please help me ?

Regards
Sajan
Tags
General Discussions
Asked by
Chris
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Malcolm
Top achievements
Rank 1
Dean Wyant
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Sajan
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or