All the other classes, such as the RowSelector and GroupMargin classes, can also be derived from to extend their functionality.
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:
A constructor that takes and instance of the derived class as a parameter.
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.
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 |
---|---|
|
C# | Copy Code |
---|---|
|
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() ); |