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

Parent Item of the Child Grid

1 Answer 37 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Levon
Top achievements
Rank 1
Levon asked on 13 Aug 2013, 07:27 PM
Hi,

I have a hierarchical grid.
So that each row has it's Child Grid. Also I have the functionality of adding new rows to my child grid.
After adding a new row to the child grid, I must save the changes, so I must have the parent object Id.

Of course I can iterate through the ItemsSource, and find the appropriate object, but it's not the best way to do this,
Is there a simpler way to obtain the Parent Item

P.S. 
All the modifications are held in ViewModel, and not in xaml.cs.

Thanks, 
Levon

1 Answer, 1 is accepted

Sort by
0
Accepted
Yoan
Telerik team
answered on 16 Aug 2013, 01:09 PM
Hi Levon,

In order to achieve your goal, you can use the ParentOfType<T> extension method like so:

private void playersGrid_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
        {
            var parentRow = (sender as RadGridView).ParentOfType<GridViewRow>();         
        }

You can check this blog post explaining how to work with the ChildrenOfType<T>() and ParentOfType<T>() extension methods. 

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Levon
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or