Xceed Grid for WinForms v4.3 Documentation
Extending other classes

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

All the other classes, such as the RowSelector and GroupMargin classes, can also be derived from to extend their functionality.

Basic steps

Although every class has various methods and properties that can be overridden, the following steps explain, in general, the minimum functions that must be implemented when creating a derived class:

  1. A constructor that takes and instance of the derived class as a parameter.

  2. An override of the CreateInstance method.

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 how to create the CustomGroupMargin class which derives from the GroupMargin class. A working version of this class can be found in the GridExtensions sample.

VB.NET Copy Code

Public Class CustomGroupMargin
  Inherits GroupMargin 

  Protected Sub New(ByVal template As CustomGroupMargin, ByVal parentGroup As Group)
    MyBase.New(template, parentGroup)
  End Sub 

  Protected Overrides Function CreateInstance(ByVal parentGroup As Group) As GroupMargin
    Return New CustomGroupMargin(Me, parentGroup)
  End Function
End Class

C# Copy Code

public class CustomGroupMargin : GroupMargin
{
  protected CustomGroupMargin( CustomGroupMargin template, Group parentGroup )
      :base( template, parentGroup )
  {
  }

  protected override GroupMargin CreateInstance( Xceed.Grid.Group parentGroup )
  {
    return new CustomGroupMargin( this, parentGroup );
  }
}

The CustomGroupMargin class can then be passed to a group at its construction and used rather than the default group margin. For example:

VB.NET Copy Code
Dim group As New Group( New CustomGroupMargin() );
C# Copy Code
Group group = new Group( new CustomGroupMargin() );