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

Best practice in many-to-many relationships?

1 Answer 211 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Johan Hedlund
Top achievements
Rank 1
Johan Hedlund asked on 03 Feb 2010, 07:37 AM
Hi!

After a quick search I discovered that many-to-many relationships aren't supported in the GridView (using data binding). But, I still need to display such data, and wonder what your recomendations are to accomplish this.

Scenario:
Two classes:
- Concert
- City

The City can host zero or many Concerts, and a Concert man be held in zero or many cities. Class definitions below:
        class Concert  
        {  
            string Name;  
            List<City> Cities;  
        }  
 
        class City  
        {  
            string Name;  
            List<Concert> Concerts;  
        } 


I load the all the Cities into a separate List<City>, and all Concerts into another List<Concert> and via another method I resolve the many-to-many relationships:
        void LoadData()  
        {  
            List<City> AllCities = LoadAllCities(); // Load data from database  
            List<Concert> AllConcerts = LoadAllConcerts(); // Load data from database  
            ResolveRelationships(AllCities, AllConcerts); // Resolve many-to-many relationship  
 
        } 
I have only created ONE object instance per City and ONE object instance per Concert. The ResolveRelationships method just reads a relation-table and populates the City.Concerts and Concert.Cities collections. The City.Concerts and Concert.Cities collections just contain references to the objects originally loaded into AllCities and AllConcerts.

Now I want to display this into a grid. The MasterGridView can contain the Concerts and the ChildGridView can contain the Cities (or vice versa).

What are your recomendations on how to accomplish this? Manually create the grid or use some kind of object datasource?

Thanks in advance,
Johan



1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 05 Feb 2010, 05:23 PM
Hello Johan Hedlund,

Thank you for writing.

RadGridView does not support building a hierarchy of custom objects with inserted List objects. However, RadGridView can handle a hierarchy from a standard DataSet object.

You have two choices for your scenario: to use a DataSet object and bind RadGridView to it, or to manually set the hierarchy in RadGridView by adding child templates and relation objects. You can find additional information on the topic in our documentation. In addition, I am attaching a sample project of a hierarchy in RadGridView where I am using custom objects as a data source.

Do not hesitate to contact me again if you have any additional questions.

Kind regards,
Martin Vasilev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Johan Hedlund
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or