New Posts New Posts RSS Feed: Refresh Collection
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Refresh Collection

 Post Reply Post Reply
Author
new user View Drop Down
Newbie
Newbie


Joined: 18-May-2011
Posts: 7
Post Options Post Options   Quote new user Quote  Post ReplyReply Direct Link To This Post Topic: Refresh Collection
    Posted: 26-May-2011 at 8:53am
 Hello,
 
 I have a RadGridView like below. It is populated using a Observabale collection of type 'ViewEmployee' which is a View. And I have a button outside GridView. clicking on that button I need to change some data in GridView(update corresponding entity). But after updation it is not refreshing the GridView.
 How could I refresh GridView or Collection.

    <telerik:RadGridView  x:Name="RadGridView1"  ItemsSource="{Binding GridViewCollection, Mode=TwoWay}" AutoGenerateColumns="False" >
     <telerik:RadGridView.Columns>
         <telerik:GridViewDataColumn DataMemberBinding="{Binding EmpID}" />
         <telerik:GridViewDataColumn DataMemberBinding="{Binding EmpName}" />
     </telerik:RadGridView.Columns>
 </telerik:RadGridView>
 
ViewModel:-

   public ObservableCollection<ViewEmployee> GridViewCollection { get; private set; }
  
   public MyViewModel()
         {
           
             GridViewCollection = new ObservableCollection<ViewEmployee>();
             var Query = mgr.ViewEmployees.Where(i => i.EmpSalary>100000);
             Query.ExecuteAsync(op => op.Results.ForEach(GridViewCollection.Add));
         }


I have tried the following code after changing the data. It is updating data in corresponding entity, but not in GridView. Once I close the applicationn and again reopen it shows the changes in GridView. Is that because I have used View to populate GridView?

 MyCommand = new RelayCommand<EventArgs>(e =>
            {
                // my code to update
                mgr.SaveChangesAsync();
                GridViewCollection .Clear();
                var Query = mgr.ViewEmployees.Where(i => i.EmpSalary>100000);
                Query.ExecuteAsync(op => op.Results.ForEach(GridViewCollection.Add));
             }

Please help.
Thanks.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 27-May-2011 at 11:57am
Hi new user;

You said that you have a button outside the grid. What exactly does that button do? Does it open up a new window where you can edit the currently selected ViewEmployee, and when you click OK, it will save the changes?

Regarding your MyCommand implementation, the re-querying should be done after the SaveChangesAsync is completed. Remember that this is an asynchronous operation.

MyCommand = new RelayCommand<EventArgs>(e =>
            {
                // my code to update
                mgr.SaveChangesAsync(saveOp => {
                   
   if(saveOp.CompletedSuccessfully) {
                   GridViewCollection .Clear();
                   var Query = mgr.ViewEmployees.Where(i => i.EmpSalary>100000);
                   Query.ExecuteAsync(op => op.Results.ForEach(GridViewCollection.Add));
   }
                });
             }
Back to Top
new user View Drop Down
Newbie
Newbie


Joined: 18-May-2011
Posts: 7
Post Options Post Options   Quote new user Quote  Post ReplyReply Direct Link To This Post Posted: 30-May-2011 at 3:25am
Hello,

yes, i m editing the currently selected ViewEmployee, and when click OK, it will save the changes. My question is do I need to to re-fetch the data again GridView to show the changes? or since  I have implemented the RaisePropertyChanged on Collection 'GridViewCllection' in the viewmodel, that will automatically notifiy the grid to reflect the changes? But the second option is not working.

But When I re-fetch the data again to GridView, it is showing updates. and also when I try the same using Database View( to populate GridView) it is not showing updates.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 31-May-2011 at 12:05pm
Thanks for the info. I'm not claiming to be a binding expert but I'm going to try and help you as best as I can.

First off, I'm still missing some bits and pieces of information here.

yes, i m editing the currently selected ViewEmployee, and when click OK, it will save the changes.

So here, you're saying that a window does pop up with the currently selected ViewEmployee and when you click OK, it will save the changes. Could you post some code showing how you're creating this window and what you're binding it to?

My question is do I need to to re-fetch the data again GridView to show the changes?

The simple answer here is no, provided that the implementation is correct.

or since  I have implemented the RaisePropertyChanged on Collection 'GridViewCllection' in the viewmodel, that will automatically notifiy the grid to reflect the changes?

I'm not sure I understand this part. I believe an ObservableCollection<T> already implements the INotifyPropertyChanged interface. Can I see your RaisePropertyChanged implementation as well?

when I try the same using Database View( to populate GridView) it is not showing updates.

I'm not sure I understand this part either. Could you elaborate?

If it's okay with you, you can also upload your entire solution (hopefully it's still small), so you don't need to keep posting code snippets.

Here are some links that should be helpful to you as you're implementing a sandbox editor. The main advice here is that you don't save the changes to the database when you click OK but rather, you use a temporary EntityManager and use ImportEntities to import the updated ViewEmployee back to the main EntityManager.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down