In the upcoming Q3 2010, we bring the extensibility of RadGridView to the next level. We will add the ability to create and replace the row type for all rows stored in the rows collection which will give our customers almost unlimited control over the customization and design of the control. The new feature gives developers the opportunity to extend the default behavior of all descends of the GridViewRowInfo class. Here is how it works:

Let’s say that you want to create an expandable filter row which has extended user-friendly UI for filtering:


In Q3 2010 this will be possible with a few simple steps. You should customize the GridViewFilteringRowInfo class by extending its child rows collection. Hence the row becomes expandable; its child row represents the outfit shown in the snapshot above. To achieve this, you should create the logical and UI representation of it by creating descendants of GridViewRowInfo and GridRowElement classes.

   1:  public class GridViewFilteringChildRowInfo : GridViewRowInfo
   2:  {
   3:   public GridViewFilteringChildRowInfo(GridViewInfo view)
   4:          : base(view)
   5:      {
   7:      }
   9:   public override AllowedGridViewRowInfoStates AllowedStates
  10:      {
  11:          get { return AllowedGridViewRowInfoStates.None; }
  12:      }
  14:   public override Type RowElementType
  15:      {
  16:          get { return typeof(GridFilteringChildRowElement); }
  17:      }
  18:  }

The AllowedStates property determines which states are supported by the row. A row can be selected, current or expanded. The GridViewFilterinChildRowInfo does not support any of them. Hence, you should override the property to return AllowedGridViewRowInfoState.None value. The RowElementType property determines the type of the visual row element that should be created for the GridViewFilterinChildRowInfo instance.

Here is the corresponding GridFilteringChildRowElement class:

   1:  public class GridFilteringChildRowElement : GridRowElement
   2:  {
   3:   private GridCellElement cellElement;
   5:   protected override void CreateChildElements()
   6:      {
   7:   base.CreateChildElements();
   9:          cellElement = new GridCellElement(null, this);
  10:          cellElement.StretchHorizontally = true;
  11:          cellElement.StretchVertically = true;
  12:   this.Children.Add(cellElement);
  14:          AdvanceFilterControl hostedControl = new AdvanceFilterControl();
  15:          RadHostItem hostItem = new RadHostItem(hostedControl);
  16:          cellElement.Children.Add(hostItem);
  17:      }
  19:   public override bool IsCompatible(GridViewRowInfo data, object context)
  20:      {
  21:   return data is GridViewFilteringChildRowInfo;
  22:      }
  23:  }

The IsCompatible method determines the compatibility with the GridViewRowInfo instances used by the RadGridView virtualization. Notice that the AdvanceFilterControl is a user control which contains the desired appearance and functionality. You have to add the row in the ChildRows collection of GridViewFilteringRowInfo by creating its descendant:

   1:  public class ExpandableGridViewFilteringRowInfo : GridViewFilteringRowInfo
   2:  {
   3:   private GridViewChildRowCollection childRows;
   5:   public ExpandableGridViewFilteringRowInfo(GridViewInfo view)
   6:          : base(view)
   7:      {
   8:   this.childRows = new GridViewChildRowCollection(this);
   9:          List<GridViewRowInfo> list = new List<GridViewRowInfo>();
  10:          list.Add(new GridViewFilteringChildRowInfo(view));
  11:   this.childRows.Load(list);
  12:      }
  14:   public override bool HasChildViews
  15:      {
  16:          get { return this.IsExpanded; }
  17:      }
  19:   public override GridViewChildRowCollection ChildRows
  20:      {
  21:          get { return this.childRows; }
  22:      }
  23:  }

The HasChildViews property determines whether the child rows are visible. Finally, you need to replace the default GridViewFilteringRowInfo instance with the custom one. You can do that by handling the GridViewTemplate.CreateRowInfo event:

   1:  private void MasterTemplate_CreateRowInfo(object sender, GridViewCreateRowInfoEventArgs e)
   2:  {
   3:   if (e.RowInfo is GridViewFilteringRowInfo)
   4:      {
   5:          e.RowInfo = new ExpandableGridViewFilteringRowInfo(e.ViewInfo);
   6:      }
   7:  }

The GridViewCreateRowInfoEventArgs instance contains two properties:

  • RowInfo that contains the instance of row that is created.
  • ViewInfo that determines the GridViewInfo instance for which the row is created.

We plan to add this feature in our upcoming Q3 release, so we will be glad to hear your comments or ideas on how to improve it.

In addition, make sure to register for What's new in Q3 2010 –WinForms and Telerik Reporting webinar, which will be part of a 5-day “Release Webinar Week”. During the week after the release you’ll have the chance to learn all the major new features that ship with the Q3 release. Book your seat for a chance to win a Telerik Premium Collection (worth $1299), a WebUI Test Studio Bundle ($2999) and a TeamPulse License for 10 users ($2490).

>> Register now

About the Author

Nikolay Diyanov

is the Product Manager of Telerik's UI for iOS and UI for Xamarin divisions. 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.


Related Posts