GrapeCity MultiRow Windows Forms Documentation
User-Defined Cell

The user-defined cell is a cell type created from the base cell or other combination of cell types as the base.

User-Defined Cell Category

The user-defined cell is created as an inherited class of an existing cell type class. Depending upon the required features, you can select any cell type as the base. For example, see the following scenarios:

In the case of adding a new property into the class inherited from a cell or built-in cell type, you need to override the Clone method and copy the value of the new property while duplicating. For more details, refer to Add Custom Property mentioned later.

Create a User-Defined Cell

The user-defined cell can be implemented through code regardless of the type of project (application, class library). You can define a cell and then register it in the toolbox, all in a project that is currently being debugged (the same way you use a user control in a Windows form).

The following steps explain how to create a user-defined cell and place it in the template designer.

  1. Open Visual Studio and create a new Windows Form Application project (for example: WindowsApplication1).
  2. From the Visual Studio menu, select Project - Add New Item.
  3. Select MultiRow 7.0 Template from the list and click on the Add button (for example: Template1.vb, Template1.cs).
  4. Once again select Project - Add New Item from the Visual Studio menu.
  5. Select Class from the list and add the class file into the project (for example: MyTextBoxCell.vb, MyTextBoxCell.cs).
  6. Open the class file and add the following code.

    [VB]

    Imports System.Drawing
    Imports System.Windows.Forms
    Imports GrapeCity.Win.MultiRow
    
    Public Class MyTextBoxCell
        Inherits TextBoxCell
        
        Public Sub New()
            Me.Style.BackColor = Color.Azure
        End Sub
    End Class
    

    [CS]

    using System.Drawing;
    using System.Windows.Forms;
    using GrapeCity.Win.MultiRow;
    
    public class MyTextBoxCell : TextBoxCell
    {
        public MyTextBoxCell()
        {
            base.Style.BackColor = Color.Azure;
        }
    }
    
  7. Build the project.
  8. Open the added template and display the Template Designer.
  9. From the Visual Studio menu, select View - ToolBox.
  10. Confirm the user-defined cell has been added to the top of the ToolBox items.

Now that the user-defined cell has been created, you can drag and drop it from the ToolBox to the Template and you can use it the same way as a built-in cell type.

Add Custom Property

Cells added to the GcMultiRow control become clones of the cell instances (GcMultiRow.Template.Row.Cells property), at runtime. So if you have created a user-defined cell and are implementing the Custom property, you need to create a duplicate of the property value in the Clone method.

Using Code

The following example creates a custom property.

[VB]

Public Class MyTextBoxCell
    Inherits TextBoxCell

    Private _editingBackColor As Color

    Property EditingBackColor() As Color
        Get
            Return _editingBackColor
        End Get
        Set(ByVal value As Color)
            _editingBackColor = value
        End Set
    End Property

End Class

[CS]

public class MyTextBoxCell : TextBoxCell
{
    private Color _editingBackColor;

    public Color EditingBackColor
    {
        get { return _editingBackColor; }
        set { _editingBackColor = value; }
    }
}

The code for the Clone method is as follows.

[VB]

Public Class MyTextBoxCell
    Inherits TextBoxCell

    Public Overrides Function Clone() As Object
        Dim myTextBoxCell As MyTextBoxCell = DirectCast(MyBase.Clone, MyTextBoxCell)
        myTextBoxCell._editingBackColor = Me.EditingBackColor
        Return myTextBoxCell
    End Function

End Class

[CS]

public class MyTextBoxCell : TextBoxCell
{
    public override object Clone()
    {
        MyTextBoxCell myTextBoxCell = base.Clone() as MyTextBoxCell;
        myTextBoxCell._editingBackColor = this.EditingBackColor;
        return myTextBoxCell;
    }
}

For more information, see the following topic:

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options