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

Object bound Hierarchy

9 Answers 191 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Todd
Top achievements
Rank 1
Todd asked on 03 Jan 2009, 12:27 PM
Telerik team,

I have been looking around on your site and found an old post that specified "Object bound Hierarchy" has not yet been 
implemented. I was wondering if it was added in a recent release, and/or if there was some kinda work around. I am trying to use the grid to create a FileExplorer that looks like the windows FileExplorer but works like the MACs Finder(you can drill down in the directories). Any help on this would be appreciated as I need to get this done and need to know if I should look somewhere else
for this behavior.

Thank you for your time.

9 Answers, 1 is accepted

Sort by
0
Jonathan Kehayias
Top achievements
Rank 1
answered on 04 Jan 2009, 03:42 AM
Todd,

I recently had the same problem and I was able to overcome it.  To provide an example:

    public partial class Form1 : Form  
    {  
        public enum AddressType  
        {  
            email,  
            home,  
            work  
        }  
        public class Person  
        {  
            public Person(string FirstName, string LastName)  
            {  
                firstname = FirstName;  
                lastname = LastName;  
            }  
 
            string firstname;  
            string lastname;  
            List<Address> addresses = new List<Address>();  
 
            public string FirstName  
            {  
                get { return firstname; }  
                set { firstname = value; }  
            }  
            public string LastName  
            {  
                get { return lastname; }  
                set { lastname = value; }  
            }  
            public List<Address> Addresses  
            {  
                get { return addresses; }  
                set { addresses = value; }  
            }  
        }  
        public class Address  
        {  
            public Address(AddressType Type, string AddressInfo)  
            {  
                type = Type;  
                addressinfo = AddressInfo;  
            }  
 
            AddressType type;  
            string addressinfo;  
 
            public AddressType Type  
            {  
                get { return type; }  
                set { type = value; }  
            }  
            public string AddressInfo  
            {  
                get { return addressinfo; }  
                set { addressinfo = value; }  
            }  
        }  
        public Form1()  
        {  
            InitializeComponent();  
 
            List<Person> people = new List<Person>();  
            Person p = new Person("Joe""Snuffy");  
            p.Addresses.Add(new Address(AddressType.email, "joesnuffy@nospam.com"));  
            p.Addresses.Add(new Address(AddressType.home, "123 Main St, Orlando, FL 33453"));  
 
            people.Add(p);  
 
            p = new Person("Mickey""Mouse");  
            p.Addresses.Add(new Address(AddressType.email, "mickey@disney.com"));  
            p.Addresses.Add(new Address(AddressType.home, "123 Main St, Orlando, FL 33453"));  
 
            people.Add(p);  
 
 
            radGridView1.AutoGenerateHierarchy = false;  
 
 
            //setup master template  
 
            GridViewTextBoxColumn textColumn = new GridViewTextBoxColumn("PersonId");  
            textColumn.IsVisible = false;  
            textColumn.VisibleInColumnChooser = false;  
            radGridView1.MasterGridViewTemplate.Columns.Add(textColumn);  
            textColumn = new GridViewTextBoxColumn("FirstName");  
            textColumn.Width = 150;  
            radGridView1.MasterGridViewTemplate.Columns.Add(textColumn);  
            textColumn = new GridViewTextBoxColumn("LastName");  
            textColumn.Width = 150;  
            radGridView1.MasterGridViewTemplate.Columns.Add(textColumn);  
 
            //setup child template  
            GridViewTemplate template = new GridViewTemplate();  
            GridViewTextBoxColumn textbox1 = new GridViewTextBoxColumn("PersonId");  
            textbox1.VisibleInColumnChooser = false;  
            textbox1.IsVisible = false;  
            template.Columns.Add(textbox1);  
            template.Columns.Add(new GridViewTextBoxColumn("AddressType"));  
            template.Columns.Add(new GridViewTextBoxColumn("AddressInfo"));  
            radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(template);  
 
            //create relation  
            GridViewRelation relation = new GridViewRelation(radGridView1.MasterGridViewTemplate);  
            relation.ChildTemplate = template;  
            relation.RelationName = "PersonToAddress";  
            relation.ParentColumnNames.Add("PersonId");  
            relation.ChildColumnNames.Add("PersonId");  
            radGridView1.Relations.Add(relation);  
 
            for (int PersonId = 0; PersonId < people.Count; PersonId++)  
            {  
                Person person = people[PersonId];  
                radGridView1.MasterGridViewTemplate.Rows.Add(PersonId, person.FirstName, person.LastName);  
 
                for (int k = 0; k < person.Addresses.Count; k++)  
                {  
                    Address address = person.Addresses[k];  
                    template.Rows.Add(PersonId, address.Type.ToString(), address.AddressInfo);  
                }  
 
            }  
        }  
    } 

You basically manually build the relations using iterators/loops over the collection.  This has worked out great for me.

The key is the manually added PersonId column which is hidden in the parent and child views.
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 21 Oct 2022, 08:40 AM

Excellent example! Thanks
0
Christian
Top achievements
Rank 1
answered on 08 Jan 2009, 11:59 AM
Hi,
following the integration of the ORM tool: Is there a more elegant way?

For suggestions, I would be grateful.
Christian
0
Nikolay
Telerik team
answered on 08 Jan 2009, 01:12 PM
Hello guys,

Todd, currently RadGridView cannot display hierarchy of bound objects automatically. You should build the hierarchy manually. You can follow the example provided by Jonathan. Another possibility for you is to make the hierarchy by having common properties for two objects. For example, in the code snippet below, Customer has CustomerId property and Order again has CustomerId property. This common property will allow you to make the necessary relation:
public partial class Form1 : Form  
{  
    public Form1()  
    {  
        InitializeComponent();  
 
        BindingList<Customers> customers = new BindingList<Customers>();  
        BindingList<Orders> orders = new BindingList<Orders>();  
 
        for (int i = 0; i < 10; i++)  
        {  
            customers.Add(new Customers(i, "John" + i.ToString()));  
            for (int j = 0; j < 5; j++)  
            {  
                orders.Add(new Orders(j, "Order" + j.ToString(), i));  
            }  
        }  
 
        radGridView1.DataSource = customers;       
        GridViewTemplate template = new GridViewTemplate();  
        template.DataSource = orders;        
        radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(template);       
        GridViewRelation relation = new GridViewRelation(radGridView1.MasterGridViewTemplate);    
        relation.ChildTemplate = template;           
        relation.RelationName = "CustomersOrders";     
        relation.ParentColumnNames.Add("CustomerId");    
        relation.ChildColumnNames.Add("CustomerId");    
        radGridView1.Relations.Add(relation);  
    }  
}  
 
public class Customers  
{  
    private int customerId;  
    private string customerName;  
 
    public Customers(int customerId, string customerName)  
    {  
        this.customerId = customerId;  
        this.customerName = customerName;  
    }  
 
    public int CustomerId  
    {  
        get 
        {  
            return customerId;  
        }  
        set 
        {  
            customerId = value;  
        }  
    }  
 
    public string CustomerName  
    {  
        get 
        {  
            return customerName;  
        }  
        set 
        {  
            customerName = value;  
        }  
    }  
}  
 
public class Orders  
{  
    private int orderId;  
    private string orderName;  
    private int customerId;  
 
    public Orders(int orderId, string orderName, int customerId)  
    {  
        this.orderId = orderId;  
        this.orderName = orderName;  
        this.customerId = customerId;  
    }  
 
    public int OrderId  
    {  
        get 
        {  
            return orderId;  
        }  
        set 
        {  
            orderId = value;  
        }  
    }  
 
    public string OrderName  
    {  
        get 
        {  
            return orderName;  
        }  
        set 
        {  
            orderName = value;  
        }  
    }  
 
    public int CustomerId  
    {  
        get 
        {  
            return customerId;  
        }  
        set 
        {  
            customerId = value;  
        }  
    }  

Jonathan, thank you for sharing your solution with the community. We appreciate it.

Christian, our ORM tool can build hierarchy of objects from a database. However, RadGridView cannot build and display this hierarchy automatically.

Regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Christian
Top achievements
Rank 1
answered on 08 Jan 2009, 01:32 PM
Hi,
it's a bit sad because the Data Form Wizard in the ORM tool is still using the Microsoft grid and therefore this wizard can't be used in practice. Do you have any time table for the migration of the dataform wizard and / or the radgridview?

Christian
0
Nikolay
Telerik team
answered on 09 Jan 2009, 12:53 PM
Hi Christian,

You can expect the migration of the dataform wizard in Q1 2009.

If you have additional questions, feel free to contact me.

Best wishes,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Christian
Top achievements
Rank 1
answered on 06 Jul 2009, 07:55 PM
Hi,
in the documentation for the current version I can not find anything on this topic. My question: Is it now possible to display hierarchical structures based on a class model?
Thank you.
Christian
0
Nikolay
Telerik team
answered on 08 Jul 2009, 03:40 PM
Hello Christian,

This feature is still not supported in RadGridView and we currently we do not have a specific time frame for its implementation. For Q2 2009 we put our efforts on the new RadDock control as well as on several other important features. For additional information, we can take a look at the What's New section.

Best wishes,
Nikolay
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
Erwin
Top achievements
Rank 1
answered on 09 Oct 2009, 11:06 PM
Hello,

It's sad that this feature has not been implemented for almost two years now since I first saw it asked by browsing the forum.
It should be simpler to implement than the data relation thing, yet it is not there yet.
:-(

I am currently evaluating the product and it is not a good point at all (especially as your product is awesome on many other aspects, so we really do not expect such a lack).

Also, why does a form take  5 seconds to load when it has a radgrid inside (only the first time)? A form with a standard datagridview shows up immediately. You can easily reproduce this problem (just create two forms, one with the rgv and one without, launched from a third one). No need to set up any properties to the rgv to see the low speed.

Thanks for your answer, and keep up the good work,

Erwin


0
Nikolay
Telerik team
answered on 15 Oct 2009, 03:50 PM
Hi Erwin,

You can find the answer to your question in this forum thread:
http://www.telerik.com/community/forums/winforms/gridview/empty-gridview-takes-5-seconds-to-show-up-hierarchical-subproperties.aspx

All the best,
Nikolay
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
Todd
Top achievements
Rank 1
Answers by
Jonathan Kehayias
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Nikolay
Telerik team
Erwin
Top achievements
Rank 1
Share this question
or