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

Nested Child Grids

15 Answers 391 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 11 Oct 2010, 01:57 PM
I have the following Grid structure:

MasterGridViewTemplate (dgTransactions) --> ChildGridTemplate1 (cSubCat)  --> ChildGridTemplate2 (cTrans)

I am populating each Template with Data but the ChildGridTemplate2 is not displaying any data - even though that the Datasource is populated with data.


Code snippet:
GridViewTemplate cSubCat = new GridViewTemplate(this.dgTransactions);
 
GridViewRelation relGridSubCat = new GridViewRelation(this.dgTransactions.MasterGridViewTemplate);
 
relGridSubCat.ChildTemplate = cSubCat;
relGridSubCat.ChildColumnNames.Add("CategoryType");
relGridSubCat.ParentColumnNames.Add("CategoryType");
 
 
this.dgTransactions.Relations.Add(relGridSubCat);
 
            this.dgTransactions.MasterGridViewTemplate.ChildGridViewTemplates.Add(cSubCat);
 
GridViewTemplate cTrans = new GridViewTemplate(this.dgTransactions);
 
             
GridViewRelation relSubCatTrans = new GridViewRelation();
relSubCatTrans.ChildTemplate = cTrans;
relSubCatTrans.ParentTemplate = this.dgTransactions.MasterGridViewTemplate.ChildGridViewTemplates[0];
relSubCatTrans.ChildColumnNames.Add("CategorySubType");
relSubCatTrans.ParentColumnNames.Add("CategorySubType");
 
             
this.dgTransactions.Relations.Add(relSubCatTrans);
 
cSubCat.ChildGridViewTemplates.Add(cTrans);
 
var sub = from x in this.CurrentTransactions
          select new { CategorySubType = x.CategorySubType, CategoryType = x.CategoryType };
 
            
             
 this.dgTransactions.DataSource = sub.Select(grp => new { grp.CategoryType }).Distinct().ToList(); ;
 
 
 cSubCat.DataSource = sub.Select(grp => new { grp.CategorySubType, grp.CategoryType }).Distinct().ToList();
 
 
cTrans.DataSource = this.CurrentTransactions.ToList();

15 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 11 Oct 2010, 03:18 PM
HI, 

I haven't managed to try this out, but this line stands out to me
relSubCatTrans.ParentTemplate = this.dgTransactions.MasterGridViewTemplate.ChildGridViewTemplates[0];

Perhaps this is selecting the wrong template to be the child. Why not just specify the actual child template.
Let me know if this doesn't work for you. 
Richard
0
Barry
Top achievements
Rank 1
answered on 11 Oct 2010, 03:25 PM
Hi Richard, Sorry, I should have mentioned before, I have tried setting it both ways. Finding the child grid within the gridview and also setting it directly. In this case assigning cSubCat as the ParentTemplate Thanks Barry
0
Emanuel Varga
Top achievements
Rank 1
answered on 11 Oct 2010, 03:30 PM
Hello Barry,

The problem here is with the fact that you are using Anonymous types, it can check the parent for the first level because that is at least an IQueryable data source, but after that the Grid cannot handle anonymous types. Please create real types and it will work fine.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Barry
Top achievements
Rank 1
answered on 12 Oct 2010, 09:33 AM
Hi Emanuel,

I have created classes and converted the Anonymous Types to these classes but it does not work.

The Master template and 1st Child template populate fine but the 2nd Child Template (linked to the 1st Child) still does not load properly.

Thanks

Barry


0
Richard Slade
Top achievements
Rank 2
answered on 12 Oct 2010, 09:45 AM
Hi Barry, 
Can you post your latest code please? 
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Oct 2010, 09:51 AM
Hello Barry,

Please see the attached example, compare it with your code and please tell me what are you doing differently

using System.Collections.Generic;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
public partial class Form1 : Form
{
    List<Person> People = new List<Person>();
    List<Part> Parts = new List<Part>();
    List<Car> Cars = new List<Car>();
 
    public Form1()
    {
        InitializeComponent();
 
        this.radGridView1.AutoGenerateHierarchy = true;
        // load primary data source
        People.Add(new Person(1, 101, "Bob", 42));
        People.Add(new Person(2, 102, "Rob", 88));
        People.Add(new Person(3, 103, "Eric", 22));
        this.radGridView1.DataSource = People;
        this.radGridView1.BestFitColumns();
 
        // Now create first relation
        GridViewTemplate carTemplate = new GridViewTemplate();
        Cars.Add(new Car(101, "Ford"));
        Cars.Add(new Car(102, "BMW"));
        Cars.Add(new Car(103, "Mazda"));
        Cars.Add(new Car(104, "Merc"));
        Cars.Add(new Car(105, "Honda"));
        carTemplate.DataSource = Cars;
 
        GridViewRelation carsRelation = new GridViewRelation(this.radGridView1.MasterTemplate);
        carsRelation.ChildTemplate = carTemplate;
        carsRelation.RelationName = "ParentChild";
        carsRelation.ParentColumnNames.Add("ID2");
        carsRelation.ChildColumnNames.Add("ID");
        this.radGridView1.Relations.Add(carsRelation);
        carTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        carTemplate.BestFitColumns();
        carTemplate.Caption = "Cars";
 
        // Now create second relation
        GridViewTemplate partsTemplate = new GridViewTemplate();
        Parts.Add(new Part(1001, 101, "Part1 for Ford"));
        Parts.Add(new Part(1002, 101, "Part2 for Ford"));
        Parts.Add(new Part(1003, 101, "Part3 for Ford"));
        Parts.Add(new Part(1004, 102, "Part1 for BMW"));
        partsTemplate.DataSource = Parts;
 
        GridViewRelation partsRelation = new GridViewRelation(carTemplate);
        partsRelation.ChildTemplate = partsTemplate;
        partsRelation.RelationName = "ParentChild";
        partsRelation.ParentColumnNames.Add("ID");
        partsRelation.ChildColumnNames.Add("CarId");
        this.radGridView1.Relations.Add(partsRelation);
        partsTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        partsTemplate.BestFitColumns();
        partsTemplate.Caption = "Parts";
 
        this.radGridView1.MasterTemplate.Templates.Add(carTemplate);
        carTemplate.Templates.Add(partsTemplate);
 
        radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    }
}
 
public class Person
{
    public int ID
    {
        get;
        set;
    }
 
    public int ID2
    {
        get;
        set;
    }
 
    public string Name
    {
        get;
        set;
    }
 
    public int Age
    {
        get;
        set;
    }
 
    public Person(int id, int id2, string name, int age)
    {
        ID = id;
        ID2 = id2;
        Name = name;
        Age = age;
    }
}
 
public class Part
{
    public int ID
    {
        get;
        set;
    }
 
    public int CarId
    {
        get;
        set;
    }
 
    public string Name
    {
        get;
        set;
    }
 
    public Part(int id, int carId, string name)
    {
        ID = id;
        CarId = carId;
        Name = name;
    }
}
 
public class Car
{
    public int ID
    {
        get;
        set;
    }
 
    public string Model
    {
        get;
        set;
    }
 
    public Car(int id, string model)
    {
        ID = id;
        Model = model;
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

*Update fixed wrong id's in parent (sorry for that - always in a hurry)

Best Regards,
Emanuel Varga
0
Barry
Top achievements
Rank 1
answered on 12 Oct 2010, 10:15 AM
Emanuel,

Thank you for the code.  I copied the code in to my solution and I get the same results.

I have attached a screen shot of the Grids.  Note that I have expanded the 3rd Grid and nothing appears apart from a small Blue rectangle.

I am using 2009 Q2 by the way

Barry
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Oct 2010, 10:48 AM
Hello Barry,

Please see my screenshot, it works as expected,

It might be an issue with the theme you are using, please consider changing to the default theme and let me know if this helped or not.

Best Regards,
Emanuel Varga
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Oct 2010, 10:52 AM
Hello again,

I've changed the theme to Breeze and everything is OK, so, the only thing left is the version, I'm using the latest version Q2 2010 SP2, please try updating to the latest version and try again.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Barry
Top achievements
Rank 1
answered on 12 Oct 2010, 10:55 AM
Hi Emanuel,

Unfortunately, I am unable to upgrade to the latest version.  I will have to take another approach to this.

I will mark your answer as the accepted answer - many thanks for all your help

thanks

Barry
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Oct 2010, 11:35 AM
Hello again,

I have an idea but you will have to test it, and I'm not 100% that it will work, you could try setting the UseScrollbarsInHierarchy to true and define a minimum ChildRowHeight, like this:

this.radGridView1.UseScrollbarsInHierarchy = true;
   
private void radGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e)
{
    e.ChildRow.Height = 200;
}

Please let me know of the outcome.

Best Regards,
Emanuel Varga
0
Barry
Top achievements
Rank 1
answered on 12 Oct 2010, 11:43 AM
Emanuel,

I don't have the setting UseScrollbarsInHierarchy - was this introduced in Q3 2009?

I have changed my approach now.  I have two grids - one contains the Categories and the other contains the SubCategories & Transactions.  When the Current Row has changed in the Categories then the other grid loads the SubCategories and related Transactions.  It doesn't look as nice but it works quite well.

Thanks

Barry
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Oct 2010, 11:46 AM
Hello again,

Sorry i couldn't help you more with this, it's very difficult to solve a problem when you have a different version of the controls.

Best Regards,
Emanuel Varga
0
Barry
Top achievements
Rank 1
answered on 12 Oct 2010, 11:48 AM
No problem at all - I know it's difficult.

Many thanks for your help - it is very much appreciated.

Barry
0
Accepted
Nikolay
Telerik team
answered on 14 Oct 2010, 09:12 AM
Hello guys,

Emanuel, thank you for your assistance.

Barry, indeed, in our older versions we had some issues with the sizes of the child views. There is no workaround that will work correctly in all cases. It will be best if you update to our latest version. If you have any issues during the transition process, do not hesitate to contact us. We will be glad to assist you further.

Greetings,
Nikolay
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
Tags
GridView
Asked by
Barry
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Barry
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or