Parent Item of the Child Grid

2 posts, 1 answers
  1. Levon
    Levon avatar
    17 posts
    Member since:
    May 2013

    Posted 13 Aug 2013 Link to this post

    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
  2. Answer
    Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 16 Aug 2013 Link to this post

    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 >>
  3. DevCraft banner
Back to Top