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

Updating the DataContext of a Row

4 Answers 291 Views
GridView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 12 Jul 2009, 12:06 PM
I need to be able to tell a GridViewRowItem to reload itself from its DataContext, but the functionality doesn't seem to be available in the current release.  To work around this, I use this logic:

object context = theRow.DataContext; 
theRow.DataContext = null
theRow.DataContext = context; 

This works fine for the standard GridViewRowItem.  Unfortunately, my grid also has a hierarchy, and so it contains GridViewExpandableRow items as well - I assumed that the same logic would cause the rows to refresh themselves, however it doesn't!

Ideally I just need to be able to tell a row to refresh itself without having to reload the entire grid.  The automatic databinding doesn't work perfectly for this, which is why I just need to tell the row to refresh itself.

Any ideas on how I can achieve what I'm attempting here?  I'm not sure whether this is a bug within the GridViewExpandableRow.

4 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 13 Jul 2009, 11:38 AM

Hi James,

RadGridView supports automatic updates of the UI without the need to rebind. However  there are some requirements :

1. If the source collection implements correctly the INotifyCollection changed, any changes to the collection will affect the UI immediately.

2. In addition  - if you need RadGridView to react to changes within the business objects in the collection, the business object itself should implement the INotifyPropertyChanged interface.

So for example if you have a collection of Persons you need to show in a RadGridView , it is good idea to use an Observable collection (point 1)  and to make the Person class implement the INotifyPropertyChanged (point 2) interface.

In this scenario you will not need a "rebind" step. And the UI will always contain an  updated info.

Kind regards,

Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
James
Top achievements
Rank 1
answered on 13 Jul 2009, 03:39 PM
Hi Pavel

Thanks for your reply.

I'm currently using an ObservableCollection, but my entities don't implement INotifyPropertyChanged. I'm not sure whether I can modify the business object to implement it, as the class is used elsewhere in the software, but I'll look into potential impacts.

If it's not possible for me to do so, is there any way for me to manually rebind the row?
0
Pavel Pavlov
Telerik team
answered on 16 Jul 2009, 04:05 PM
Hello James,

I am not sure if this can help but  you can try directly updating the values of the cells in the row :

here is some sample code (updates the first cell of the first row).

GridViewExpandableRow row1 = this.RadGridView1.ItemsControl.VirtualizingPanel.ChildrenOfType<GridViewExpandableRow>()[0];

((GridViewCell)row1.Cells[0]).Value = "test";


This is as far as I can get with the current version of the RadGridView. I will also take care for this one to be improved for our next release

Sincerely yours,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
James
Top achievements
Rank 1
answered on 17 Jul 2009, 05:41 AM
Hi Pavel

Thanks for your reply.  I actually managed to implement the INotifyPropertyChanged interface and it all works fine for me.

I think that there is potential for users to have business objects that can't implement this property though.  For cases like this it might be useful to have RefreshRowData() or something similar, that just tells the row to reload itself from its DataContext.
Tags
GridView
Asked by
James
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
James
Top achievements
Rank 1
Share this question
or