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

Multiple child tables in hierachical radgridview

18 Answers 851 Views
GridView
This is a migrated thread and some comments may be shown as answers.
branko
Top achievements
Rank 1
branko asked on 14 Apr 2009, 12:33 PM
I managed to make RadGridView show multiple related tables (LINQ to SQL) by approach used in FirstLook sample (create GridViewTableDefinition and TableRelation). If I add two table definitions it works OK (besides showing empty table if no related record exists).
I'd like to know if there exists a way, to show each of related tables in separate tab of RadTabControl. If I define HierarchyChildTemplate/DataTemplate with RadTabControl where each tab containins GridViewDataControl, I get two tab-controls instead of one, first one showing first relation on all tabs and second tab-control showing second related table on all tabs. Is there a Way to show child-table per tab-item (or expander or something alike)?

Thanks.
Branko

18 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 17 Apr 2009, 11:53 AM
Hi branko,

You can customize a little the style of the ChildDataControlsPresenter control as shown in the attached example.

Sincerely yours,
Nedyalko Nikolov
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
branko
Top achievements
Rank 1
answered on 19 Apr 2009, 03:18 PM
Thank you for informative example. While it shows nice approach to my problem, I still don't know how to show different child table in each tab. I modified your example by adding another property of same class (named cancelled orders), then adding PropertyRelation to that property. While each tab in tab control shows name of different relation in it's header, both grids in tab-bodies show same (first) table. 

So am I missing some binding (perhaps in telerik:GridViewDataControl) or something?

Thanks in advance. O:-Z
0
Accepted
Nedyalko Nikolov
Telerik team
answered on 23 Apr 2009, 07:24 AM
Hi branko,

I'm attaching a modified version of the example that you already have. I replaced the GridViewDataControl in the ChildDataControlPresenter template with the RadGridView object, because there were some problems with the GridViewDataControl within the TabContol. We are doing our best to fix them. Until then I think this workaround will be helpful.

Greetings,
Nedyalko Nikolov
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
branko
Top achievements
Rank 1
answered on 23 Apr 2009, 11:23 AM
Thanks.

Your sample solves the problem.

I actually need something a little bit different, which I managed to chew through by studying that sample: details in one tab, and related tables in other two, which can also be done by specifying custom style for ChildDataControlsPresenter and manual binding. Not the most elegant solution, but it works:
            <Style TargetType="telerik:ChildDataControlsPresenter"
                <Setter Property="Template"
                    <Setter.Value> 
                        <ControlTemplate TargetType="telerik:ChildDataControlsPresenter"
                            <TabControl> 
                                <TabItem Header="Details"
                                    <StackPanel DataContext="{Binding MasterRecord.Data}"
                                        <Label Content="{Binding Name}" /> 
                                        <Label Content="{Binding Age}" /> 
                                        <Label Content="..." /> 
                                    </StackPanel> 
                                </TabItem> 
                                <TabItem Header="Orders"
                                    <telerik:RadGridView ItemsSource="{Binding MasterRecord.Data.Orders}" /> 
                                </TabItem> 
                                <TabItem Header="Cancelled Orders"
                                    <telerik:RadGridView ItemsSource="{Binding MasterRecord.Data.CancelledOrders}" /> 
                                </TabItem> 
                            </TabControl> 
                        </ControlTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
 
 
 



0
branko
Top achievements
Rank 1
answered on 23 Apr 2009, 11:32 PM
And now to next problem... :)

Using approach described in previous post I can't manually define grid's columns. If I use AutoGenerateColumns="False", i always get autogenerated columns + additional manually defined ones. I guess it's a bug?

Example (only part of above style):
                                <TabItem Header="Orders"
                                    <telerik:RadGridView  
                                        ItemsSource="{Binding MasterRecord.Data.Orders}"  
                                        AutoGenerateColumns="False"
                                        <telerik:RadGridView.Columns> 
                                            <telerik:GridViewDataColumn HeaderText="id" DataMemberPath="ID" /> 
                                        </telerik:RadGridView.Columns> 
                                    </telerik:RadGridView> 
                                </TabItem> 
 
 

The grid gets ID, description and one more id.
0
Vlad
Telerik team
answered on 24 Apr 2009, 06:04 AM
Hi branko,

Please set DataContext for the grid to null and let me know about the result. Here is an example:

<telerik:RadGridView  ItemsSource="{Binding MasterRecord.Data.Orders}" 
                   DataContext="{x:Null}" AutoGenerateColumns="False">
    <telerik:RadGridView.Columns>
       <telerik:GridViewDataColumn HeaderText="id" DataMemberPath="ID" />
   </telerik:RadGridView.Columns>
</telerik:RadGridView>

Best wishes,
Vlad
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
branko
Top achievements
Rank 1
answered on 24 Apr 2009, 06:44 AM
>Please set DataContext for the grid to null and let me know about the result

In modified sample Nedyalko posted, setting DataContext to Null makes only specified column header(s) visible. But there is no data shown in grid (only correct header).
In my actual application (Linq to SQL ItemsSource) there is no header(s) and no data after same modification. 
0
Nedyalko Nikolov
Telerik team
answered on 28 Apr 2009, 08:36 AM
Hi branko,

You can add GridViewDataColumns in xaml file, in the attached example you can see how to do that. Code in xaml is actually commented but works fine. There is a single restriction about this method, the "issue" is that all child grids will have the same columns (if that not troubles you this is the preferred way).

If you want child grids to have different columns you can use Loaded and DataContextChange events. At Loaded you can initialize columns and DataContextChange is fired when Tab item is changed.

Hope this will help. Let me know about the result.

Greetings,
Nedyalko Nikolov
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
branko
Top achievements
Rank 1
answered on 04 May 2009, 07:43 PM
I had no problem defining grid columns in XAML. 

Now, thanks to your example, I also know how to modify child grids programmatically on opening. It is perhaps one way to solve my problem, but I'd like to avoid it, if it's possible.

What bothers me, is... well, first excerpt from my form source. Data source is LINQ to SQL...

<Grid> 
    <Grid.Resources> 
        <Style TargetType="telerik:ChildDataControlsPresenter"
            <Setter Property="Template"
                <Setter.Value> 
                    <ControlTemplate TargetType="telerik:ChildDataControlsPresenter"
                        <TabControl
                            <TabItem Header="Details"
                                <my:UserControlPatientDetails DataContext="{Binding MasterRecord.Data}" /> 
                            </TabItem> 
                            <TabItem Header="Contacts"
                                <telerik:RadGridView ItemsSource="{Binding MasterRecord.Data.Addresses}"  
                                                     IsFilteringAllowed="False"  
                                                     ColumnsWidthMode="Fill"  
                                                     ShowGroupPanel="False" 
                                                     AutoGenerateColumns="False"
                                    <telerik:RadGridView.Columns> 
                                        <telerik:GridViewDataColumn HeaderText="street (only column)" DataMemberPath="StreetLine_1" /> 
                                    </telerik:RadGridView.Columns> 
                                </telerik:RadGridView> 
                            </TabItem> 
                        </TabControl> 
                    </ControlTemplate> 
                </Setter.Value> 
            </Setter> 
        </Style> 
    </Grid.Resources> 
 
    <telerik:RadGridView Name="gridPatients" AutoGenerateColumns="False" AutoGenerateHierarchyFromDataSet="False"
        <telerik:RadGridView.Columns> 
            <telerik:GridViewDataColumn HeaderText="pat.no." DataMemberPath="PAT_ID" IsReadOnly="True" /> 
            <telerik:GridViewDataColumn HeaderText="sirname" DataMemberPath="Sirname" /> 
            <telerik:GridViewDataColumn HeaderText="SSN" DataMemberPath="SocialSecNo" /> 
        </telerik:RadGridView.Columns> 
    </telerik:RadGridView> 
</Grid> 
 
 

ChildDataControlsPresenter is restyled to show up as tabcontrol, one tab showing master record details, other showing related table (patients' address). Patient's address child grid should only show one column (street) - since AutoGenerateColumns for that RadGridView is set to false.
But what actually happens is that grid shows all columns first (all public properties of Addresses class) and after that street (once more). I would like it to show only street.

Is there a way to acomplish this? Is there perhaps a better way (compared to above "hack") to make grid show a "plus sign" and then make it show custom subform?

Thanks again.
0
Nedyalko Nikolov
Telerik team
answered on 07 May 2009, 10:42 AM
Hi branko,

The problem with the AutoGenerateColumns property on the child grid is a known issue for us.
Problem actually is connected with the DataContext which is set to the child RadGridView. I'm attaching a working example (modified version of the one you already have) how to work around this issue and you can choose between two hacks.

Unfortunately some other GridView logic stops us from fixing this issue immediately. We are doing our best in order to improve this code as soon as possible.

About the "plus" sign and details preview this is in our TODO list for the 2009_Q2 release.

Sorry for the inconvenience caused.

All the best,
Nedyalko Nikolov
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
branko
Top achievements
Rank 1
answered on 07 May 2009, 01:28 PM
Thank you again. That solves my problem. :)

Also nice to hear details feature is planned.
0
Meisam
Top achievements
Rank 1
answered on 28 Jul 2009, 10:37 AM
Hi Nedyalko,

I have about 10 gridview in my project and each one maybe has one or more child table definition. I want to use your approach to show each child in a tab control, but because of binding gridview(in ContentTemlate of the TabItem) every properties in the sub collection appears as a column that i don't want this!
you attached a example code for doing this, but I think i can't do that in that way because I should know that the current child is from which parent gridview and is which of it's child table definitions. Also I don't want that the column's header and property name be same.
without tabItem I do that with defining columns for each child:
GridViewDataColumn columnCI_NAME = new GridViewDataColumn();     
columnCI_NAME.DataMemberBinding = new Binding("CI_NAME");     
columnCI_NAME.HeaderText = "CI NAME";     
detailDefinition.FieldDescriptors.Add(columnCI_NAME);   
 

but in your approach I can't use that!
I will be thankful if I know your solution!

Regards ;)
0
Nedyalko Nikolov
Telerik team
answered on 30 Jul 2009, 08:18 AM
Hi Meisam,

I think that "Row Details" feature of the RadGridView is what you need. This feature gives you possibility to set custom template for details view (which if you put in this template RadGridView it becomes a hierarchy example), and do not need to use Generic template for ChildDataControlsPresenter.

I'm attaching a sample project for Silverlight which you can use for reference how to meet your goals, because situation is identical for WPF.

Hope this helps.

Best wishes,
Nedyalko Nikolov
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
Meisam
Top achievements
Rank 1
answered on 02 Aug 2009, 07:10 AM
Hi Nedyalko,

thanks so much for your example, but Unfortunately my visual studio(2008 pro) can't open that !!!
I open your xamls and classes in other project! my gridview doesn't have RowDetails maybe because of versioning(I have version 2009.1.312.35)! secondly I think I can't use it in this way!
We have a service that retrives data with Linq to SQL, the client app recieve data from service and data is in collection and have some subcollection in it! I can't define gridview columns in xamle and should define that programmatically in such a way that I explained before!

Regards ;)
0
Nedyalko Nikolov
Telerik team
answered on 03 Aug 2009, 03:53 PM
Hello Meisam,

You can use LoadingRowDetails event to customize columns of the child grid.
I'm attaching a modified version of the example you already have.

Indeed "Row Details" feature was introduced with 2009.Q2 release, so I'm attaching an example with regular property hierarchy.

Hope this helps.

Kind regards,
Nedyalko Nikolov
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
Wael Slaman
Top achievements
Rank 1
answered on 14 Dec 2009, 04:16 PM
Hello Telerik Team,

I managed to make RadGridView show multiple related tables (LINQ to SQL) by approach used in FirstLook sample (create GridViewTableDefinition and TableRelation). If I add two table definitions it works OK (besides showing empty table if no related record exists).
I'd like to know if there exists a way, to show each of related tables in separate tab of RadTabControl.


I have used your attached solution , but one problem that I have is that I can not see the tab header name.
I am uploading my project so may you can tell me what is the problem.


http://www.zshare.net/download/698869532cfb7498/

Thank you
Wael
0
shadhan
Top achievements
Rank 1
answered on 18 Dec 2009, 09:50 AM

Hi team,

I have done a hierachical model using the attached sample
How can i hide a specific column in the gridview

I used RadGridView1.Columns[0].IsVisible property
But its not working, and it shows the actual column count as 0
How can i sove this issue

Please help...
0
Nedyalko Nikolov
Telerik team
answered on 21 Dec 2009, 02:09 PM
Hello Shanthi Gangatharan,

Can you provide me with more information about when are you call GridViewColumn.IsVisible = false? Generally this should work, so if it does not work it should be investigated, but I need some more info (a sample project which I can debug on my side will be great).

Hello Wael,

You are trying to bind to the "TableDefinition.Relation.Name" property which is not available for the TabItem.DataContext (in your example this data context is the selected Order). TableDefinition object is used internally to set the required data context. Please take a look at this code snippet based on your example:

<Grid Loaded="Grid_Loaded">
        <Grid.Resources>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="Header" Value="{Binding}"/>
                <Setter Property="BorderThickness" Value="1,1,0,1"/>
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <telerik:RadGridView ItemsSource="{Binding Details}" />
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
 
            <Style TargetType="telerik:ChildDataControlsPresenter">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="telerik:ChildDataControlsPresenter">
                            <TabControl Name="PART_ChildDataItemsControl"
                                        ItemsSource="{Binding}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
 
        <telerik:RadGridView Name="radGridView1"
                             ScrollMode="Deferred"
                             ClipToBounds="True"
                             FlowDirection="LeftToRight"
                             MultipleSelect="True"
                             telerik:StyleManager.Theme="Office_Black"
                             Margin="0,0,0,12" />
    </Grid>


Best wishes,
Nedyalko Nikolov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
branko
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
branko
Top achievements
Rank 1
Vlad
Telerik team
Meisam
Top achievements
Rank 1
Wael Slaman
Top achievements
Rank 1
shadhan
Top achievements
Rank 1
Share this question
or