Creating child tables programatically

7 posts, 0 answers
  1. Hugo Aristizabal
    Hugo Aristizabal avatar
    22 posts
    Member since:
    Jan 2010

    Posted 19 May 2010 Link to this post

    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.
  2. Hugo Aristizabal
    Hugo Aristizabal avatar
    22 posts
    Member since:
    Jan 2010

    Posted 19 May 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 20 May 2010 Link to this post

    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.
  5. Hugo Aristizabal
    Hugo Aristizabal avatar
    22 posts
    Member since:
    Jan 2010

    Posted 20 May 2010 Link to this post

    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.
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 21 May 2010 Link to this post

    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.
  7. Hugo Aristizabal
    Hugo Aristizabal avatar
    22 posts
    Member since:
    Jan 2010

    Posted 21 May 2010 Link to this post

    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.
  8. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 26 May 2010 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready