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

Creating child tables programatically

8 Answers 205 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hugo Aristizabal
Top achievements
Rank 2
Hugo Aristizabal asked on 19 May 2010, 10:29 PM
Hi, how can I programatically add child tables and relations (hierarchies) to a WPF RadGridView? Can I add more than one level of hierarchies?

I need to create something like a master/details view in my RadGridView, but every detail can have its own details as well (that's why I need more that one level of hierarchies).

Thanks a lot.

8 Answers, 1 is accepted

Sort by
0
Hugo Aristizabal
Top achievements
Rank 2
answered on 19 May 2010, 10:44 PM
I saw something like this in another forum post, but it applies to winforms, not WPF:

radGridView1.DataSource = nwindDataSet.Suppliers; 
 
GridViewTemplate template = new GridViewTemplate(); 
template.DataSource = nwindDataSet.Products; 
radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(template); 
 
GridViewRelation relation = new 
     GridViewRelation(radGridView1.MasterGridViewTemplate); 
relation.ChildTemplate = template; 
relation.RelationName = "SuppliersProducts"
relation.ParentColumnNames.Add("SupplierID"); 
relation.ChildColumnNames.Add("SupplierID"); 
radGridView1.Relations.Add(relation); 

Something like that would be excatly what I need, because basically I got a DataSet with DataTables that have DataRelations between them, can something like that apply to WPF? What other approach can you suggest?

Thanks again.
0
Maya
Telerik team
answered on 20 May 2010, 03:51 PM
Hello Hugo Aristizabal,

I believe this forum thread will be helpful in your case, especially as you can download a sample project. It is for Silverlight, but you can easily implement it to WPF.
If you have any further questions, please do not hesitate to get back to us.
 

Sincerely yours,
Maya
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
Hugo Aristizabal
Top achievements
Rank 2
answered on 20 May 2010, 05:06 PM
Thanks, the project is interesting, and it gives me a clue. However, I'm still stuck at something. Here's what my problem looks like:

I have my original GridView bound to a DataSet's first table, called "Years". Table "Years" has a column (amongst others) called "Year", which is the column I'm trying to create the relation from. The DataSet's also got another table called "Semesters", which also has a column called "Year", and it also has a column called "Semester" and some other more. Finally, I got a third table called "Months", which has, amongst others, two columns, "Year" and "Semester".

What I need to do is to let the user see all the columns from table Years first, and then create a hierarchy for each year's semester, and then another hierarchy for each semester's month.

By looking at the code provided in th thread you suggested me, I notice that you created a Relation and added it to the grid, but the example shows a relation to the same data. The thing I can't figure out is how to bind the inside grids to the respective DataTable.

Thanks a lot.
0
Maya
Telerik team
answered on 21 May 2010, 12:12 PM
Hi Hugo Aristizabal,

 
If I understand correctly, you want to create three-layer hierarchy - the Parent is the "Year" and for every row "Semester" comes out as a Child. And in the end "Month" appears as a child of "Semester".
There are a couple of ways that you can create multi-level hierarchy.
Firstly, you may define them in xaml. In the parent grid you need to define  its ChildTableDefinitions and HierarchyChildTemplate. Furthermore, in order to create the second level of hierarchy, you have to define its ChildTableDefinitions and HierarchyChildTemplate. You may use as a reference this blog post, which probably does not cover exactly your case, but it will give the basic idea of creating three-level hierarchy.
Furthermore, you may use the Property Relation of the grid and to specify the property that connects the levels of the hierarchy. You may take a look at this forum thread.
Another possible solution is to define the hierarchy and the property Relation in the code-behind.
I am sending you a sample project that demonstrates some of those cases. 
However, you can always use as a reference our online documentation.


Kind regards,
Maya
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
Hugo Aristizabal
Top achievements
Rank 2
answered on 21 May 2010, 02:42 PM
Thanks for your feedback. With your code I was able to create the hierarchies, but then I found out that what I need to do probably can't be done. Here's why:

Relations are defined with a PropertyRelation object, that takes the (only one) column you want to relate the parent and child table. But what I actually need to do requieres the relation to have more than one column. Check this example of what my DataSet would look like:

Table YEARS:
Year   CompanyName      ManagerName
2010    AAAAA                    MMMMM
2010    BBBBB                    NNNNNN

Table SEMESTERS:
Year    Semester    CompanyName     ManagerName
2010     1                   AAAAA                    MMMMM
2010     2                   AAAAA                    MMMMM
2010     1                   BBBBB                    NNNNNN
2010     2                   BBBBB                    NNNNNN

Table MONTHS:
Year    Semester    Month       CompanyName     ManagerName
2010     1                   Apr              AAAAA                  MMMMM
2010     1                   May             AAAAA                  MMMMM
2010     2                   Aug             AAAAA                  MMMMM
2010     2                   Nov             AAAAA                  MMMMM
2010     1                   Feb             BBBBB                  NNNNNN
2010     2                   Oct              BBBBB                  NNNNNN
2010     2                   Nov              BBBBB                 NNNNNN

What the user needs is to be able to see data by year, and then be able to "zoom in" the details of  each semester, and again of each month (actually I got trimesters, weeks and days as well, but the general idea is the same). One problem is, for instance, that the relation between table YEARS and table SEMESTERS isn't by the Year column only, but by CompanyName and ManagerName columns as well, because obvioulsy for year 2010 I got two records, one for each company.

The other problem is that the user wants to be able to select any period as his starting point. So he may choose to see all the way from the years down, or only from the semesters down, or only the months.

I'm going to have to talk to my user about it, because I loosing a lot of time trying to figure this out, and I haven't been able to get anywhere.

Thanks anyway for your great help, as always.
0
Maya
Telerik team
answered on 26 May 2010, 03:13 PM
Hello Hugo Aristizabal,

When creating complicated relations in a hierarchy you may try to use View Models and to bind every one of them to the desired state of the application. 
I hope that helps.

Regards,
Maya
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
Kesav
Top achievements
Rank 1
answered on 15 Sep 2017, 05:20 PM
Does version 2010.2.0924.35 have the capability being discussed in this post?
0
Stefan
Telerik team
answered on 20 Sep 2017, 12:43 PM
Hello Kesav,

I checked out the earlier versions of our components and it seems that the hierarchy of RadGridView is available for the 2010.2.0924 version. This can also be observed in the sample application provided by my colleague, as it references even older binaries. Can you please take a look at it?

Regards,
Stefan X1
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Hugo Aristizabal
Top achievements
Rank 2
Answers by
Hugo Aristizabal
Top achievements
Rank 2
Maya
Telerik team
Kesav
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or