Xceed Grid for WinForms v4.3 Documentation
Extending the Row class

Welcome to Xceed Grid for WinForms v4.3 > Advanced Concepts > Extending the grid's classes > Extending the Row class

The Row class as well as all the classes that derive from the Row class can be derived from to create custom row classes. To create a row class that contains cells, it is necessary to derive from the CellRow class, or one of its derived classes, rather than directly from the Row class. To create a row class that does not contain cells, then you can derive directly from the Row class or any other of the row classes that do not contain cells.

Basic steps

When creating a class that derives from the Row class or one of its derived classes, the following minimum functions must be implemented:

  1. A public constructor with no parameters.

  2. A protected constructor that receives an instance of the derived class as a parameter.

  3. An override of the CreateInstance method.

  4. When deriving directly from the CellRow class, an override for the CellType property must also be added.

When creating a class that derives from the CellRow class or one of its derived classes, the following minimum functionalities need to be implemented:

  1. A public constructor with no parameters.

  2. A protected constructor that receives an instance of the derived class as a parameter.

  3. An override of the CreateCell   method.

  4. An override of the CreateInstance method.

The newly created classes can then be used seamlessly within Xceed Grid for WinForms. For example, because the row class in the demonstration below derives from the DataRow class, it can be used as a template to create the data rows that will populate the grid. This is done by assigning a new instance of the class to the GridControl's DataRowTemplate property.

VB.NET Copy Code
GridControl1.DataRowTemplate = New ImageRow()
C# Copy Code
gridControl1.DataRowTemplate = new ImageRow();

The GridElement class implements the IComponent interface which derives from the IDisposable interface. This allows each grid element to be a component in the Grid Designer and thus individually selectable. It is not necessary however to call the Dispose method on the GridElement class nor on any class that derives from the GridElement class.

When creating a class that derives from GridElement (or any of its derived classes), code should not be placed within the IDisposable.Dispose method since Dispose will not be called.

Demonstration

The following example demonstrates the minimum implementation required for a class that derives from the DataRow class. A working version of this class can be found in the in the Puzzle sample.

VB.NET Copy Code

Public Class ImageRow
  Inherits DataRow 

  Public Sub New()
    MyBase.New()
  End Sub 

  Protected Sub New(ByVal template As ImageRow)
    MyBase.New(template)
  End Sub 

  ' Necessary only if you want to use your row in the Grid Designer
  Public Sub New( ByVal rowSelector As RowSelector )
    MyBase.New( rowSelector )
  End Sub 

  Protected Overrides Function CreateCell(ByVal parentColumn As Column) As Cell
    Return New ImageCell(parentColumn)
  End Function 

  Protected Overrides Function CreateInstance() As Row
    Return New ImageRow(Me)
  End Function
End Class

C# Copy Code

public class ImageRow : DataRow
{
  public ImageRow()
   : base()
  {
  }

  protected ImageRow( ImageRow template )
   : base( template )
  {
  }

  // Necessary only if you want to use your row in the Grid Designer
  public ImageRow( RowSelector rowSelector )
 :base( rowSelector )
 
{
  }

  protected override Cell CreateCell( Column parentColumn )
  {
    return new ImageCell( parentColumn );
  }

  protected override Row CreateInstance()
  {
    return new ImageRow( this );
  }
}

Things you should consider