In our previous blog post we showed how to use the new RadGridView Object-Relational Hierarchy with the Entity Framework. The same scenario can be easily implemented with Telerik OpenAccess ORM. The OpenAccess wizard for adding a new DomainModel will help us build the model of the well-known Northwind database in a few easy steps:
Once this is done, the auto-generation of the hierarchy is very simple and needs just a few lines of code. We only need the LINQ query to the root object used for a DataSource (in our case “Suppliers”) and then setting AutoGenerateHierarchy to true:
NorthwindEntities entities =
var query = from suppliers
entities.Suppliers select suppliers;
.radGridView1.DataSource = query.ToList();
The result is self-explanatory:
Although this was nice and quick, this scenario does not take into account further presentation tweaking, because it was auto-generated. In cases when you need to fine-tune the visible data and its presentation, you will need to manually add the Object-Relational hierarchy. The key thing in this setup is to add a relation that contains only one ChildColumnNames, i.e. the name of the IEnumerable/IList property used for loading the second data level (which is always loaded on expand through lazy loading):
sender, EventArgs e)
var query = from customers
entities.Customers select customers;
GridViewTemplate childTemplate = CreateChildTemplate();
GridViewRelation relation =
GridViewTemplate childTemplate =
GridViewTextBoxColumn column =
childTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
You can then apply the needed column formatting in the respective section. The result (without any modifications of the above code) is as follows:
The source code of example can be downloaded from here (link). It uses RadControls for WinForms Q3 2010, which you can download here.
Next time we will show you how to use the Load on Demand hierarchy with WCF data service.
Enjoy, and don’t forget to leave your comments!
Nikolay Diyanov Diyanov is the Product Manager of the Native Mobile UI division at Progress. Delivering outstanding solutions that make developers' lives easier is his passion and the biggest reward in his work. In his spare time, Nikolay enjoys travelling around the world, hiking, sun-bathing and kite-surfing.
Find him on Twitter @n_diyanov or on LinkedIn.