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

Hierarchy with

6 Answers 182 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 22 Sep 2010, 04:51 PM
*edit* Forgot to title the post properly! Should be "Hierarchy with multiple child datasources" Feel free to correct this admins!

I've got a code defined hierarchy to work fine in C#, with a RadGridView with a datasource etc and then defined a template with a relation and a datasource for the child rows and assigned these to the RadGridView.

This works fine and the '+' expands and shows the child rows.

What I want to do though is have the expanded child row be from a different datasource depending on some value in the parent. Ie what expands has different columns depending on the parent row.

I can't seem to specify more than one datasource for the childrows.
What I want to see is:

AAA BBB CCC                      (Parent row)
--d e f                                    (Expanded child row)
AAA2 BBB2 CCC2                 (Parent row)
--g h i                                     (Expanded child, different columns/datasource to the other child row)

The parent rows have the same columns/datasource.
The child rows have different columns/datasource.

Is this possible and can both different child rows be expanded at the same time?

6 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 24 Sep 2010, 11:49 AM
Hi David, 

As far as I know this wouldn't be possible. The rows under any parent row are all part of the same template, and therefore all part of the same data source. 
I think you would need to sort out your child datasource so that you can display both types of data. 
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 24 Sep 2010, 02:33 PM
Hello David,

Before proceeding with this you should read this document (Difference between GridViewInfo.Rows and GridViewTemplate.Rows)  where it is explained why you would not be able to have two different data sources for child rows, sorry.

But honestly I'm very curios if there is a way to achieve this, i could see this as being something useful in the future. I will do some tests and let you know if i turn up something useful.

Best Regards,
Emanuel Varga
0
David
Top achievements
Rank 1
answered on 27 Sep 2010, 01:55 PM
I seem to have semi managed what I wanted...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
using Telerik.WinControls.UI;
 
namespace Telerik_Hierarchy
{
    public partial class Form1 : Form
    {
        List<Person> People = new List<Person>();
        List<Address> Houses = new List<Address>();
        List<Car> Cars = new List<Car>();
 
        GridViewTemplate carTemplate = new GridViewTemplate();
        GridViewTemplate houseTemplate = new GridViewTemplate();
 
        public Form1()
        {
            InitializeComponent();
            this.radGridView1.AutoGenerateHierarchy = true;
 
            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();
 
 
 
            Houses.Add(new Address(1, 44, "Badger street"));
            Houses.Add(new Address(2, 16, "Fish street"));
            Houses.Add(new Address(3, 18, "Goat road"));
 
 
            Cars.Add(new Car(101, "Ford"));
            Cars.Add(new Car(101, "BMW"));
            Cars.Add(new Car(101, "Mazda"));
            Cars.Add(new Car(102, "Merc"));
            Cars.Add(new Car(103, "Honda"));
 
 
            // Now create relations
            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.BestFitColumns();
            carTemplate.Caption = "Cars";
 
            houseTemplate.DataSource = Houses;
            GridViewRelation houseRelation = new GridViewRelation(this.radGridView1.MasterTemplate);
            houseRelation.ChildTemplate = houseTemplate;
            houseRelation.RelationName = "ParentChild";
            houseRelation.ParentColumnNames.Add("ID");
            houseRelation.ChildColumnNames.Add("ID");
            this.radGridView1.Relations.Add(houseRelation);
            houseTemplate.BestFitColumns();
            houseTemplate.Caption = "Houses";
 
            this.radGridView1.MasterTemplate.Templates.Add(houseTemplate);
            this.radGridView1.MasterTemplate.Templates.Add(carTemplate);
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            this.radGridView1.BestFitColumns();
        }
    }
 
    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 Address
    {
        public int ID { get; set; }
        public int Number { get; set; }
        public string Street { get; set; }
 
        public Address(int id, int number, string street)
        {
            ID = id;
            Number = number;
            Street = street;
        }
    }
 
 
    public class Car
    {
        public int ID { get; set; }
        public string Model { get; set; }
 
        public Car(int id, string model)
        {
            ID = id;
            Model = model;
        }
    }
 
}

This gives the attached output, which is pretty much what I want.
I need to be able to programtically hide/show the "Houses"/"Cars" tabs though.

Have I done something terrible in doing this? OR did I just not phrase the question very well?  :-)
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 28 Sep 2010, 07:12 AM
Hello again,

I think i misunderstood what you meant, i was thinking that you wanted something like a car list for one person and JUST a house list for another person, but in any case , in my point of view the best way of achieving your desired effect is to somehow access the TabStrip inside the child row and just close one of the tabs and select the other one on ChildViewExpanding or on ChildViewExpanded, but i haven't yet figured it out how to get to that

Update... i found an answer here, but sadly it is not possible to do that, if you really want to i might be able to help you some other way, but it is more complicated and more error prone without extensive testing, but if you really want to please let me know and i will try to help you.

Best Regards,
Emanuel Varga
0
David
Top achievements
Rank 1
answered on 29 Sep 2010, 04:20 PM
It would be helpful to be able to, but its not a disaster if its not possible.
Seems odd that the tabs are generated, but then there's no way to access/manipulate them via the API.

Thanks for your input on this.
0
Julian Benkov
Telerik team
answered on 05 Oct 2010, 12:01 PM
Hello David,

Thank you for writing to us.

This functionality is not supported in RadGridView. You can add two child views in the parent collection and have two different DataSources and Columns, but this a valid case for the GridViewTemplate level and not for the row level. For more details about this scenario, please review our Examples application, section GridView >> Hierarchy >> Tab Child Views.

I hope this was helpful.

Kind regards,
Julian Benkov
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
David
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Emanuel Varga
Top achievements
Rank 1
David
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or