menu

WinForms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class GridCellModelBase - WindowsForms API Reference | Syncfusion

    Show / Hide Table of Contents

    Class GridCellModelBase

    Defines the data or model part of a cell type. Settings can be serialized out to a file together with a GridModel.

    Inheritance
    System.Object
    NonFinalizeDisposable
    Disposable
    GridCellModelBase
    XhtmlCellModel
    GridCheckBoxCellModel
    GridDataBoundRowExpandCellModel
    GridPushButtonCellModel
    GridRichTextBoxCellModel
    GridStaticCellModel
    GridTableIndentCellModel
    PivotRowExpandCellModel
    Implements
    System.Runtime.Serialization.ISerializable
    System.IDisposable
    Inherited Members
    NonFinalizeDisposable.Dispose(Boolean)
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Syncfusion.Windows.Forms.Grid
    Assembly: Syncfusion.Grid.Windows.dll
    Syntax
    public class GridCellModelBase : Disposable, ISerializable, IDisposable
    Remarks

    You typically access cell models through the CellModels property of the GridModel class.

    A GridCellModelBase can serve as model for several GridCellRendererBase instances if there are several GridControlBase views for a GridModel. The following table illustrates the built-in cell model types available in Essential Grid.

    Cell TypesDescription
    CheckBoxSets the specified cell as "CheckBox" in the grid, which returns the check state of that specified cell. Refer the GridCheckBoxCellModel and GridCheckBoxCellRenderer class.
    ColorEditSets the specified cell to edit the backcolor of the cell. The range of colors can be chosen from either the Color palette,Web or System tabs in the drop-down menu. Refer the GridDropDownColorUICellModel and GridDropDownColorUICellRenderer class.
    ComboBoxSets a Combo-box embedded in the specified grid cell, where a specified data source can be assigned and also the button visibility can be modified. Refer the GridComboBoxCellModel and GridComboBoxCellRenderer class.
    ControlEmbeds a generic control withe the grid cell. Refer the GridGenericControlCellModel and GridGenericControlCellRenderer class.
    CurrencyEmbeds a currency edit cell. The values entered in this cell are prefixed with a specified currency-symbol. Refer the GridCurrencyTextBoxCellModel and GridCurrencyTextBoxCellRenderer class.
    DropDownGridSets a Grid in the drop-down container. See "Drop-Down grid" in the samples. Also refer the GridDropDownGridCellModel and GridDropDownGridCellRenderer class.
    FormulaCellGets a formula cell that can be used for various computational operations in the grid using the library functions. Also, a custom-function can be added to the library functions to meet the required need. Refer the GridFormulaCellModel and GridFormulaCellRenderer class.
    GridListControlEmbeds a GridListControl in the specified cell. Refer the GridDropDownGridListControlCellModel and GridDropDownGridListControlCellRenderer class.
    HeaderSpecifies the cell as Header cell. Refer the GridHeaderCellModel and GridHeaderCellRenderer class.
    ImageSpecifies the cell as an Image cell, where a required image can be displayed on the grid. Refer the GridImageCellModel and GridImageCellRenderer class.
    MaskEditSpecifies the textbox as a masked-edit textbox, where specified criteria can be set to validate the user inputs. Refer the GridMaskEditCellModel and GridMaskEditCellRenderer and GridMaskedEditBoxclass.
    MonthCalendarGets a month-calendar control for acquiring a "Date" input from the grid cell. Refer the GridDropDownMonthCalendarCellModel and GridDropDownMonthCalendarCellRenderer class.
    NumericUpDownEmbeds a Numeric up-down control in the specified grid cell. The increment and decrement values as well as the Minimum and Maximum number-count possible can also be modified as per the need. Refer the GridNumericUpDownCellModel and GridNumericUpDownCellRenderer class.
    OriginalTextBoxSets the specified cell as "OriginalTextBox", that provides a multi-line text box. Refer the GridOriginalTextBoxCellModel and GridOriginalTextBoxCellRenderer class.
    ProgressBarEmbeds a progress bar control in the specified cell. Refer the GridProgressBarCellModel and GridProgressBarCellRenderer class.
    PropertyGridCellSets the specified cell as property-grid, that displays the property's values in the grid. Refer the GridPropertyGridCellModel and GridPropertyGridCellRenderer class.
    PushButtonSets the specified cell as "PushButton" control. The cell appearance can also be modified. Refer the GridPushButtonCellModel and GridPushButtonCellRenderer class.
    RadioButtonSets the specified cell as "RadioButton" control. Refer the GridRadioButtonCellModel and GridRadioButtonCellRenderer class.
    RichTextSets the specified cell as a "RichTextBox" control. The contents of the cell can also be formated such as Alignment, Bold or Italics or Under lined, Font size as well as font color and font type. Refer the GridRichTextBoxCellModel and GridRichTextBoxCellRenderer class.
    StaticSets the specified cell in an in-active state and the contents of the specified cell is non-editable. Refer the GridStaticCellModel and GridStaticCellRenderer class.
    TextBoxSets the specified cell as"TextBox" control. The default cell model of every grid cell is a TextBox model. Refer the GridTextBoxCellModel and GridTextBoxCellRenderer class.
    UITypeEditorCellSpecifies the cell as UI-type editor cell that provides a "list-control" like grid. Refer the GridUITypeEditorCellModel and GridUITypeEditorCellRenderer class.

    Constructors

    GridCellModelBase(GridModel)

    Initializes a new GridCellModelBase object and stores a reference to the GridModel this cell belongs to.

    Declaration
    public GridCellModelBase(GridModel grid)
    Parameters
    Type Name Description
    GridModel grid

    The GridModel that owns this model.

    GridCellModelBase(SerializationInfo, StreamingContext)

    Initializes a new GridCellModelBase from a serialization stream.

    Declaration
    protected GridCellModelBase(SerializationInfo info, StreamingContext context)
    Parameters
    Type Name Description
    System.Runtime.Serialization.SerializationInfo info

    An object that holds all the data needed to serialize or deserialize this instance.

    System.Runtime.Serialization.StreamingContext context

    Describes the source and destination of the serialized stream specified by info.

    Properties

    BindingContext

    Gets or sets the BindingContext for this object. You can assign a BindingContext form a parent form to this property.

    Declaration
    public BindingContext BindingContext { get; set; }
    Property Value
    Type
    System.Windows.Forms.BindingContext

    ButtonBarSize

    Gets or sets the total size of any buttons.

    Declaration
    public Size ButtonBarSize { get; set; }
    Property Value
    Type
    System.Drawing.Size
    Remarks

    Set size.Height to int.MaxValue if button should fill cell and not be vertically aligned with text.

    Description

    Gets a description of the cell type.

    Declaration
    public virtual string Description { get; }
    Property Value
    Type
    System.String

    ForceCoveredCellFullBounds

    Gets or sets a value indicating whether covered cells need to be drawn passing in the complete coordinates of the covered cell even if parts of the covered cell are above the current view.

    Declaration
    public bool ForceCoveredCellFullBounds { get; set; }
    Property Value
    Type
    System.Boolean
    Remarks

    If you expect your cell type to be used in a scenario where a cell can span over 100s of rows, you should set this property to true and provide an optimized draw routine in the cell renderer that accepts a clipped rectangle.

    The GridGroupingControls GridNestedTableControl uses this flag to optimize drawing of nested tables. Nested tables are all drawn in a child cell and can span thousands of rows. Instead of calculating the whole rectangle for the nested cell, the grid can pass in just the visible bounds. This improves performance of these nested cells a lot.

    Grid

    Gets a reference to the GridModel.

    Declaration
    public GridModel Grid { get; }
    Property Value
    Type
    GridModel

    IsDisposed

    Gets a value indicating whether the object has been disposed.

    Declaration
    public bool IsDisposed { get; }
    Property Value
    Type
    System.Boolean

    IsDisposing

    Gets a value indicating whether the object is executing Dispose() method call.

    Declaration
    public bool IsDisposing { get; }
    Property Value
    Type
    System.Boolean

    MeasureEmptyCellString

    Gets or sets the string which is used when doing a resize to fit for cells with empty text.

    Declaration
    public static string MeasureEmptyCellString { get; set; }
    Property Value
    Type
    System.String

    SerializeSchemeVersion

    Gets the version information when cell model is deserialized.

    Declaration
    public int SerializeSchemeVersion { get; }
    Property Value
    Type
    System.Int32

    Methods

    ApplyFormattedText(GridStyleInfo, String, Int32)

    Parses the display text and converts it into a cell value to be stored in the style object. GridStyleInfo.CultureInfo is used for parsing the string.

    Declaration
    public virtual bool ApplyFormattedText(GridStyleInfo style, string text, int textInfo)
    Parameters
    Type Name Description
    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    System.String text

    The input text to be parsed.

    System.Int32 textInfo

    TextInfo is a hint of who is calling, default is GridCellBaseTextInfo.DisplayText

    Returns
    Type Description
    System.Boolean

    True if value was parsed correctly and saved in style object as CellValue; False otherwise.

    ApplyText(GridStyleInfo, String)

    Parses the text and converts it into a cell value to be stored in the style object (ignoring any Format settings). CultureInfo.CurrentText is used for parsing the string.

    Declaration
    public virtual bool ApplyText(GridStyleInfo style, string text)
    Parameters
    Type Name Description
    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    System.String text

    The input text to be parsed.

    Returns
    Type Description
    System.Boolean

    True if value was parsed correctly and saved in style object as CellValue; False otherwise.

    CalculatePreferredCellSize(Graphics, Int32, Int32, GridStyleInfo, GridQueryBounds)

    Calculates the preferred size of the cell based on its contents, including margins and any buttons.

    Declaration
    public virtual Size CalculatePreferredCellSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
    Parameters
    Type Name Description
    System.Drawing.Graphics g

    The System.Drawing.Graphics context of the canvas.

    System.Int32 rowIndex

    The row index.

    System.Int32 colIndex

    The column index.

    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    GridQueryBounds queryBounds

    Vertical or horizontal

    Returns
    Type Description
    System.Drawing.Size

    The optimal size of the cell.

    CreateCopy(GridModel)

    Creates a copy of this cell model for another GridModel.

    Declaration
    public virtual GridCellModelBase CreateCopy(GridModel gridModel)
    Parameters
    Type Name Description
    GridModel gridModel

    The GridModel for the new control.

    Returns
    Type Description
    GridCellModelBase

    Returns the instance of the grid model

    CreateRenderer(GridControlBase)

    Creates a renderer for this cell model that is specific to the GridControlBase.

    Declaration
    public virtual GridCellRendererBase CreateRenderer(GridControlBase control)
    Parameters
    Type Name Description
    GridControlBase control

    The GridControlBase the cell renderer is created for.

    Returns
    Type Description
    GridCellRendererBase

    A new GridCellRendererBase specific for a GridControlBase.

    Remarks

    You must override this method in your implementation of GridCellModelBase.

    Dispose()

    Releases the all resources used by the component.

    Declaration
    public void Dispose()

    GetActiveText(Int32, Int32)

    Declaration
    public string GetActiveText(int rowIndex, int colIndex)
    Parameters
    Type Name Description
    System.Int32 rowIndex
    System.Int32 colIndex
    Returns
    Type
    System.String

    GetCellClientSize(Int32, Int32, GridStyleInfo)

    Declaration
    public Size GetCellClientSize(int rowIndex, int colIndex, GridStyleInfo style)
    Parameters
    Type Name Description
    System.Int32 rowIndex
    System.Int32 colIndex
    GridStyleInfo style
    Returns
    Type
    System.Drawing.Size

    GetCellSize(Int32, Int32)

    Declaration
    public Size GetCellSize(int rowIndex, int colIndex)
    Parameters
    Type Name Description
    System.Int32 rowIndex
    System.Int32 colIndex
    Returns
    Type
    System.Drawing.Size

    GetFormattedOrActiveTextAt(Int32, Int32, GridStyleInfo)

    Returns the display text of the specified cell. If it is the current cell the active text is returned.

    Declaration
    public string GetFormattedOrActiveTextAt(int rowIndex, int colIndex, GridStyleInfo style)
    Parameters
    Type Name Description
    System.Int32 rowIndex

    The row index.

    System.Int32 colIndex

    The column index.

    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    Returns
    Type Description
    System.String

    A System.String with the display text of the specified cell.

    GetFormattedText(GridStyleInfo, Object, Int32)

    This is called from GridStyleInfo.GetFormattedText. GridStyleInfo.CultureInfo is used for conversion to string.

    Declaration
    public virtual string GetFormattedText(GridStyleInfo style, object value, int textInfo)
    Parameters
    Type Name Description
    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    System.Object value

    The value to format.

    System.Int32 textInfo

    TextInfo is a hint of who is calling, default is GridCellBaseTextInfo.DisplayText.

    Returns
    Type Description
    System.String

    The formatted text for the given value.

    GetLocalizedString(String)

    Returns a localized string from the SR.txt resource file.

    Declaration
    protected virtual string GetLocalizedString(string value)
    Parameters
    Type Name Description
    System.String value

    The key to look up.

    Returns
    Type Description
    System.String

    The localized string.

    GetObjectData(SerializationInfo, StreamingContext)

    Implements the ISerializable interface and returns the data needed to serialize the cell model.

    Declaration
    public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
    Parameters
    Type Name Description
    System.Runtime.Serialization.SerializationInfo info

    A SerializationInfo object containing the information required to serialize the cell model.

    System.Runtime.Serialization.StreamingContext context

    A StreamingContext object containing the source and destination of the serialized stream.

    GetPropertyDescriptor(GridStyleInfo)

    Returns GridStyleInfo.PropertyDescriptor.

    Declaration
    public virtual PropertyDescriptor GetPropertyDescriptor(GridStyleInfo style)
    Parameters
    Type Name Description
    GridStyleInfo style

    The style object

    Returns
    Type Description
    System.ComponentModel.PropertyDescriptor

    A PropertyDescriptor

    GetText(GridStyleInfo, Object)

    This is called from GridStyleInfo.GetText (ignoring any Format settings). CultureInfo.CurrentText is used for conversion to string.

    Declaration
    public virtual string GetText(GridStyleInfo style, object value)
    Parameters
    Type Name Description
    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    System.Object value

    The value to convert to a string.

    Returns
    Type Description
    System.String

    The string that represents the given value.

    GetTypeConverter(GridStyleInfo)

    Returns a TypeConverter with type information about the style.CellValue.

    Declaration
    public virtual TypeConverter GetTypeConverter(GridStyleInfo style)
    Parameters
    Type Name Description
    GridStyleInfo style

    The style object

    Returns
    Type Description
    System.ComponentModel.TypeConverter

    A TypeConverter

    MeasureSampleWString(Graphics, Font)

    Gets the preferred size to be used for an empty cell.

    Declaration
    public static Size MeasureSampleWString(Graphics g, Font font)
    Parameters
    Type Name Description
    System.Drawing.Graphics g

    The System.Drawing.Graphics context of the canvas.

    System.Drawing.Font font

    The System.Drawing.Font to be used.

    Returns
    Type Description
    System.Drawing.Size

    The System.Drawing.Size of the given string specified with it's font type.

    OnActiveTextChanged(GridCellEventArgs)

    Recalculates floating cell state and raises the ActiveTextChanged event.

    Declaration
    protected virtual void OnActiveTextChanged(GridCellEventArgs e)
    Parameters
    Type Name Description
    GridCellEventArgs e

    A GridCellEventArgs with event data.

    OnBindingContextChanged(EventArgs)

    Called when the BindingContext property was changed.

    Declaration
    protected virtual void OnBindingContextChanged(EventArgs e)
    Parameters
    Type Name Description
    System.EventArgs e

    An empty EventArgs

    OnModelDeserialization(Object, GridModel)

    Called from GridModel implementation of IDeserializationCallback.OnDeserialization.

    Declaration
    protected virtual void OnModelDeserialization(object sender, GridModel model)
    Parameters
    Type Name Description
    System.Object sender

    The source of the event.

    GridModel model

    The GridModel that was deserialized.

    OnQueryCanFloatCell(Int32, Int32, GridStyleInfo, GridQueryFloatCell)

    Determines whether the cell supports floating over a neighboring cell or can be flooded by a previous cell.

    Declaration
    public virtual bool OnQueryCanFloatCell(int rowIndex, int colIndex, GridStyleInfo style, GridQueryFloatCell query)
    Parameters
    Type Name Description
    System.Int32 rowIndex

    The row index.

    System.Int32 colIndex

    The column index.

    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    GridQueryFloatCell query

    A GridQueryFloatCell value that specifies whether a cell is asked about support for floating over another cell or being flooded by a previous cell.

    Returns
    Type Description
    System.Boolean

    True if floating is possible; False otherwise.

    OnQueryCanMergeCell(Int32, Int32, GridStyleInfo, GridMergeCellDirection)

    Determines whether the cell supports merging of neighboring cells.

    Declaration
    public virtual bool OnQueryCanMergeCell(int rowIndex, int colIndex, GridStyleInfo style, GridMergeCellDirection mergeCellDirection)
    Parameters
    Type Name Description
    System.Int32 rowIndex

    The row index.

    System.Int32 colIndex

    The column index.

    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    GridMergeCellDirection mergeCellDirection

    Specifies if rows or columns should be merged.

    Returns
    Type Description
    System.Boolean

    True if merging is possible; False otherwise.

    OnQueryPrefferedClientSize(Graphics, Int32, Int32, GridStyleInfo, GridQueryBounds)

    Calculates the preferred size of the cell based on its contents without margins and any buttons.

    Declaration
    protected virtual Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
    Parameters
    Type Name Description
    System.Drawing.Graphics g

    The System.Drawing.Graphics context of the canvas.

    System.Int32 rowIndex

    The row index.

    System.Int32 colIndex

    The column index.

    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    GridQueryBounds queryBounds

    Graphical bounds

    Returns
    Type Description
    System.Drawing.Size

    The optimal size of the cell.

    ResetActiveText(Int32, Int32)

    Reset the active text to its original state.

    Declaration
    public void ResetActiveText(int rowIndex, int colIndex)
    Parameters
    Type Name Description
    System.Int32 rowIndex

    The row index.

    System.Int32 colIndex

    The column index.

    SetActiveText(Int32, Int32, String)

    Changes the active text for the cell model.

    Declaration
    public void SetActiveText(int rowIndex, int colIndex, string text)
    Parameters
    Type Name Description
    System.Int32 rowIndex

    The row index.

    System.Int32 colIndex

    The column index.

    System.String text

    The new text for the cell.

    Examples

    This example shows how to set the text in a given cell index.

    void gridControl1_CellClick(object sender, GridCellClickEventArgs e)
    {
        string text="GridControl";
        this.gridControl1.CurrentCell.Model.SetActiveText(e.RowIndex, e.ColIndex, text);
    }
    Private Sub gridControl1_CellClick(ByVal sender As Object, ByVal e As GridCellClickEventArgs)
        Dim text As String="Active Text"
        Me.gridControl1.CurrentCell.Model.SetActiveText(e.RowIndex, e.ColIndex, text)
    End Sub

    SubtractBorders(Rectangle, GridStyleInfo)

    Removes border margins from a given cell rectangle. The borders are determined from a specified style with cell content information.

    Declaration
    [Obsolete("It is recommended to specify isRightToLeft parameter, default for isRightToLeft is false.")]
    public Rectangle SubtractBorders(Rectangle cellBounds, GridStyleInfo style)
    Parameters
    Type Name Description
    System.Drawing.Rectangle cellBounds

    The System.Drawing.Rectangle with the cell bounds.

    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    Returns
    Type Description
    System.Drawing.Rectangle

    The System.Drawing.Rectangle with the cell bounds excluding its borders.

    Remarks

    calls GridMargins.RemoveMargins(cellBounds, StyleInfoBordersToMargins(style));

    Examples

    This example shows how to remove the border margins from given cell rectangle.

    void gridControl1_CellClick(object sender, GridCellClickEventArgs e)
    {
        //Removes border margins from a given cell rectangle.
        GridRangeInfo range = this.gridControl1.Model.CoveredRanges.FindRange(e.RowIndex, e.ColIndex);
        Rectangle rect = this.gridControl1.RangeInfoToRectangle(range);
        this.gridControl1.CurrentCell.Model.SubtractBorders(rect, style, true); 
    }
    Private Sub gridControl1_CellClick(ByVal sender As Object, ByVal e As GridCellClickEventArgs)
       'Removes border margins from a given cell rectangle.
        Dim range As GridRangeInfo = Me.gridControl1.Model.CoveredRanges.FindRange(e.RowIndex, e.ColIndex)
        Dim rect As Rectangle = Me.gridControl1.RangeInfoToRectangle(range)
        Me.gridControl1.CurrentCell.Model.SubtractBorders(rect, style, True)
    End Sub

    SubtractBorders(Rectangle, GridStyleInfo, Boolean)

    Removes border margins from a given cell rectangle. The borders are determined from a specified style with cell content information.

    Declaration
    public Rectangle SubtractBorders(Rectangle cellBounds, GridStyleInfo style, bool isRightToLeft)
    Parameters
    Type Name Description
    System.Drawing.Rectangle cellBounds

    The System.Drawing.Rectangle with the cell bounds.

    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    System.Boolean isRightToLeft

    Indicates if grid is in RightToLeft mode.

    Returns
    Type Description
    System.Drawing.Rectangle

    The System.Drawing.Rectangle with the cell bounds excluding its borders.

    Remarks

    Calls GridMargins.RemoveMargins(cellBounds, StyleInfoBordersToMargins(style));

    Events

    ActiveTextChanged

    Occurs when active text has been changed.

    Declaration
    public event GridCellEventHandler ActiveTextChanged
    Event Type
    Type
    GridCellEventHandler

    Implements

    System.Runtime.Serialization.ISerializable
    System.IDisposable
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved