Can your grid control do this? Part II

by XAML Team | Comments 4

title

In my previous post I told you about the new interesting feature in RadGridView for WinForms - Row Layout customization. I also promised to provide some additional details about this feature, so here they are.

The view definition in RadGridView not only changes the row layout, it specifies the behavior and the appearance of the grid. All view definitions implement the IViewDefinition interface and you could create your own definitions, if you wish. To change the default view definition in RadGridView you need just to set the ViewDefinition property:

this.radGridView1.ViewDefinition = myViewDefinition;

We have included three different view definitions in our Q3 release. They are: TableViewDefinition, ColumnGroupsViewDefinition and HtmlViewDefinition. We plan to extend their functionality and to add new view definitions (for example the long awaited card view) in near future. Currently there is no graphical tool to customize them, but you should use code to do the magic. We are currently working on a graphical designer for this feature and it will be revealed soon.

Now let me explain how to use the different view definitions:

The TableViewDefinition is the default view. It contains all features of the standard table presentation that existed in the old RadGridView. The data is presented like a table and you can reorder, hide and pin columns. This is a typical table view:

table

 
ColumnGroupsViewDefinition
- As its name suggests, this view enables grouping of columns. Every column group can have an unlimited number of sub groups or rows containing columns. To start using this view definition you need to add some groups:

ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();

view.ColumnGroups.Add(new GridViewColumnGroup("Customer"));
view.ColumnGroups.Add(new GridViewColumnGroup("Details"));
view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Address"));
view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Contact"));

Then add at least one row which to contain the desired columns:

view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["ID"]);
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Name"]);
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Family"]);

Here is the result:

grouping

 
Of course, the ColumnGroupsViewDefinition enables resizing of column groups:

grouping3

 
HtmlViewDefinition -
The name of this view may lead to some confusion. No, RadGridView doesn't support html rendering, and we don't have plans to support it. Nevertheless, this view enables using row layout similar to the one existing in html tables. In fact, you can take an existing html table and use its html code in RadGridView. Sometimes this can save a lot of work. Just change the cell text to be the unique name of the desired column.

To use the HTML view just add rows and cells:

HtmlViewDefinition view = new HtmlViewDefinition();

view.RowTemplate.Rows.Add(new RowDefinition());
view.RowTemplate.Rows.Add(new RowDefinition());

view.RowTemplate.Rows[0].Cells.Add(new CellDefinition("ID"));
view.RowTemplate.Rows[0].Cells.Add(new CellDefinition("Name"));
view.RowTemplate.Rows[0].Cells.Add(new CellDefinition("City"));
view.RowTemplate.Rows[0].Cells.Add(new CellDefinition("Country"));
view.RowTemplate.Rows[1].Cells.Add(new CellDefinition("Phone"));

Then we could specify some row and column spans:
view.RowTemplate.Rows[0].Cells[2].RowSpan = 2;
view.RowTemplate.Rows[0].Cells[3].RowSpan = 2;
view.RowTemplate.Rows[1].Cells[0].ColSpan = 2;

The code above can be replaced with the following html:

<table>
<tr>
<td>ID</td>
<td>Name</td>
<td rowspan=""2"">City</td>
<td rowspan=""2"">Country</td>
</tr>
<tr>
<td colspan=""2"">Phone</td>
</tr>
</table>

You should use the ReadXml method of HtmlViewDefinition to load the definition.

And the result:

html

 
Note:
I should point out that we support only a small piece of the functionality of the real html table. For example we don't support table headers or CSS.

These are our first steps in customizing row layouts and we intend to extend the functionality in our upcoming releases. Therefore, your feedback is highly appreciated. Any ideas, comments or suggestions are welcome.

About the author

Nikolay Diyanov

Nikolay Diyanov

is the Program Manager of Telerik's WinForms division. He joined the company back in 2007 as a Support Officer and made his way up the ladder over the past few years. 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.

@n_diyanov

4 Comments

Peter Kellner
Very nice examples of the Grid!  and, love the new web site.
Steven
The new customizable row layout possibilities are great and I would love to see them extended further :)
Nhilesh Baua
1. Can you please update the telerik grid version information?
2. Does CellDefinitions are only sufficient enough to bind the data in customized format?

Thanks
Nhilesh Baua
Srividhya
Nice example. I need the same kind of grid(i.e example of HtmlViewDefinition) to be created by using the asp:GridView or telerik:RadGrid control. Please send me the samples if you know the properties.

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by XAML Team - or - read latest articles in Developer Tools
Product Families