Telerik blogs

In addition to the fact that our next release focuses mostly on our accessibility and automated testing as described in this blog post, in our upcoming version we will include many bug fixes in all RadControls for WinForms, including a highly optimized version of RadTreeView.

In this article however, we want to present a new interesting feature in RadGridView that you will surely find useful. A customer of ours requested a mixed hierarchy mode where he wanted to use a self-reference hierarchy AND the classic hierarchy mode together. The scenario that he described used a file explorer where the main level presented a folder tree, and a nested level displaying file properties.



All this will be possible in the next GridView version with just a few lines of code. For Q1 2011 we have extended the auto-generated hierarchy mode and now you can specify all relations directly in the data set. Here is what you will need to do:

1. First create a new DataTable that will contain all folders and put some data in it:

DataTable folders = new DataTable("folders");
folders.Columns.Add ("ID", typeof(int));
folders.Columns.Add ("ParentID", typeof(int));
folders.Columns.Add ("Name", typeof(string));
folders.Columns.Add ("Size", typeof(int));

2. Then create a table that will contain the files' properties and add some file data:

DataTable files = new DataTable("files");
files.Columns.Add ("ID", typeof(int));
files.Columns.Add ("FolderID", typeof(int));
files.Columns.Add ("Name", typeof(string));
files.Columns.Add ("Size", typeof(int));
files.Columns.Add ("DateModified", typeof(DateTime));

3. Specify all relations directly in the data set. RadGridView will recognize them automatically. The following code creates a new DataSet and initializes the necessary data relations:


DataSet dataSet = new DataSet();
dataSet.Tables.Add (folders);
dataSet.Tables.Add (files);
dataSet.Relations.Add (new DataRelation ("FoldersSelfRef", folders.Columns["ID"], folders.Columns["ParentID"]));
dataSet.Relations.Add (new DataRelation ("FoldersFiles", folders.Columns["ID"], files.Columns["FolderID"]));


4. As a final step, assign the DataMember and DataSet properties and set the AutoGenerateHierarchy property to true:


this.radGridView1.DataSource = dataSet;
this.radGridView1.DataMember = "folders";
this.radGridView1.AutoGenerateHierarchy = true;


Soon we will reveal even more new features coming in Q1 2011, so do not forget to subscribe for our rss feed. If you have any feedback or ideas that you want to share, we will be glad to hear them.

About the Author

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.

Related Posts


Comments are disabled in preview mode.