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

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

The Cell class as well as all the classes that derive from the Cell class can be derived from to create custom cell classes. Theses classes can then be used as normal to populate custom row classes. For example, the DataCell class derives from the Cell class and is used to populate DataRows which derive from the CellRow class.

Basic steps

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

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

  2. A public constructor that receives an instance of a Column object as a parameter.

  3. An override of the CreateInstance method.

  4. When deriving directly from the Cell class, an override for the SetValue and GetValue methods must also be added.

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 DataCell class. A working version of this class can be found in the in the Puzzle sample.

VB.NET Copy Code

Public Class ImageCell
  Inherits DataCell 

  Protected Sub New(ByVal template As ImageCell)
    MyBase.new(template)
  End Sub 

  Public Sub New(ByVal parentColumn As Column)
    MyBase.new(parentColumn)
  End Sub 

  Protected Overrides Function CreateInstance() As Cell
    Return New ImageCell(Me)
  End Function
End Class

C# Copy Code

public class ImageCell : DataCell
{
  protected ImageCell( ImageCell template )
   : base( template )
  {
  }

  public ImageCell( Column parentColumn )
   : base( parentColumn )
  {
  }

  protected override Cell CreateInstance()
  {
    return new ImageCell( this );
  }
}