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

Parent-Child Grids Bound To The Same Context/Record

6 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vassili King
Top achievements
Rank 1
Vassili King asked on 03 Aug 2010, 02:51 PM
Hello,

Is there a way to have two grids (parent and child) bind to the same context?  I'm trying to have a child grid display additional fields that are not displayed in the parent grid row.  It is similar to "click here for more info on this record" approach, but done via a child grid or a something similar to the Grid demo at http://demos.telerik.com/silverlight/#GridView/FirstLook.

Thank you!

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Aug 2010, 03:48 PM
Hello,

 There will be no problem to do that since both row-details and hierarchy child template are with the same DataContext as parent row. 

All the best,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vassili King
Top achievements
Rank 1
answered on 03 Aug 2010, 04:08 PM
That's what I've heard.  However, the child grid has no data (I've double-checked the bindings).  I must be missing something. Here is how it looks like:

<telerik:RadGridView Name="rgvMainGrid" IsReadOnly="True" ShowGroupPanel="False" AutoGenerateColumns="False" ItemsSource="{Binding v_GenericView}">
            <telerik:RadGridView.ChildTableDefinitions>
                <telerik:GridViewTableDefinition />
            </telerik:RadGridView.ChildTableDefinitions>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" />
                <telerik:GridViewDataColumn Header="Email" DataMemberBinding="{Binding Email}" />
                <telerik:GridViewDataColumn Header="Title" DataMemberBinding="{Binding Title}" />
                <telerik:GridViewDataColumn Header="Office" DataMemberBinding="{Binding Office}" />
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <telerik:RadGridView IsReadOnly="True" ShowGroupPanel="False" AutoGenerateColumns="False">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" />
                            <telerik:GridViewDataColumn Header="Dept" DataMemberBinding="{Binding Dept}" />
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </DataTemplate>
            </telerik:RadGridView.HierarchyChildTemplate>
        </telerik:RadGridView>

This yields a grid with parent rows bound and child nodes empty.

Any suggestions would be greatly appreciated.

Thank you!
0
Vlad
Telerik team
answered on 03 Aug 2010, 04:11 PM
Hello,

 You have not set ItemsSource for the child grid. 

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vassili King
Top achievements
Rank 1
answered on 03 Aug 2010, 04:49 PM
If I set the ItemsSource to the same "{Binding v_GenericView}", there is no change.  Since I'm trying to pull data from the same record (just split between parent and child grids), I'm not sure that creating a different data source would be a good idea.  What's left to try?

Thank you!
0
Accepted
Vlad
Telerik team
answered on 03 Aug 2010, 05:00 PM
Hi,

 You cannot use v_GenericView since this the list with parent items however DataContext in this template is item part of this list. Do you need grid (or ItemsControl) at all here? You can use directly TextBlock - for example:

 <telerik:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </telerik:RadGridView.HierarchyChildTemplate>


Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vassili King
Top achievements
Rank 1
answered on 03 Aug 2010, 05:27 PM
This did it.  That is, using TextBlock instead of the Grid.  I've tried this approach earlier, but must have messed up something in the binding and so it did not work.  Now things seem to be working fine. 

Thanks a lot for all your help!
Tags
GridView
Asked by
Vassili King
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Vassili King
Top achievements
Rank 1
Share this question
or