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

Reflecting Custom Object Changes in RGV Hierarchy

1 Answer 27 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 07 Oct 2014, 06:40 PM
Hi,

I am using the hierarchy feature of the data grid. My data consist of two custom objects one composed of the other.

class MyClassA : INotifyPropertyChanged
{
    String Porperty1 {get; set;}
    BindiingList<MyClassB> Items {get; set;}
    //...
}
 
class MyClassB : INotifyPropertyChanged{
    String Property1 {get; set;}
    int Property2{ get; set;}
    //...
}
(My actual classes invoke the PropertyChanged event. I did not show the full setters here for simplicity.)

I am setting a BindingList<MyClassA> as the data source for the grid view. I understand from this post here that you must handle the change event on the data grid when using the hierarchy view. I did this below:

private void dataGrid_CellValueChanged(object sender, GridViewCellEventArgs e)
        {
            //if the column is from the child view we must handle the change to the data model directly
            if(e.Column.OwnerTemplate == gridViewTemplate1)
            {
                var b = e.Row.DataBoundItem as MyClassB;
                var property = typeof(MyClassB).GetProperty(e.Column.FieldName);
                property.SetValue(b, e.Value, null);
            }
        }

This works for updating the data model when changes are made to the UI. How do I see changes reflected in the UI when changes are made to the model?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Oct 2014, 01:24 PM
Hello Chris,

Thank you for writing.

In order to reflect changes to the RadGridView immediately after the update process, I would suggest you to use two separate BindingLists for each template. If the custom object implements INotifyPropertyChanged interface, the respective template will be notified for the changes. Please refer to the attached sample project. On a timer tick, there are updated and added objects and the changes are refreshed at once.   

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Desislava
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or