Export (0) Print
Expand All

DataGridViewCell Class

Represents an individual cell in a DataGridView control.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public abstract class DataGridViewCell : DataGridViewElement, 
	ICloneable, IDisposable

The DataGridViewCell type exposes the following members.

  NameDescription
Protected methodDataGridViewCellInitializes a new instance of the DataGridViewCell class.
Top

  NameDescription
Public propertyAccessibilityObjectGets the DataGridViewCell.DataGridViewCellAccessibleObject assigned to the DataGridViewCell.
Public propertyColumnIndexGets the column index for this cell.
Public propertyContentBoundsGets the bounding rectangle that encloses the cell's content area.
Public propertyContextMenuStripGets or sets the shortcut menu associated with the cell.
Public propertyDataGridViewGets the DataGridView control associated with this element. (Inherited from DataGridViewElement.)
Public propertyDefaultNewRowValueGets the default value for a cell in the row for new records.
Public propertyDisplayedGets a value that indicates whether the cell is currently displayed on-screen.
Public propertyEditedFormattedValueGets the current, formatted value of the cell, regardless of whether the cell is in edit mode and the value has not been committed.
Public propertyEditTypeGets the type of the cell's hosted editing control.
Public propertyErrorIconBoundsGets the bounds of the error icon for the cell.
Public propertyErrorTextGets or sets the text describing an error condition associated with the cell.
Public propertyFormattedValueGets the value of the cell as formatted for display.
Public propertyFormattedValueTypeGets the type of the formatted value associated with the cell.
Public propertyFrozenGets a value indicating whether the cell is frozen.
Public propertyHasStyleGets a value indicating whether the Style property has been set.
Public propertyInheritedStateGets the current state of the cell as inherited from the state of its row and column.
Public propertyInheritedStyleGets the style currently applied to the cell.
Public propertyIsInEditModeGets a value indicating whether this cell is currently being edited.
Public propertyOwningColumnGets the column that contains this cell.
Public propertyOwningRowGets the row that contains this cell.
Public propertyPreferredSizeGets the size, in pixels, of a rectangular area into which the cell can fit.
Public propertyReadOnlyGets or sets a value indicating whether the cell's data can be edited.
Public propertyResizableGets a value indicating whether the cell can be resized.
Public propertyRowIndexGets the index of the cell's parent row.
Public propertySelectedGets or sets a value indicating whether the cell has been selected.
Public propertySizeGets the size of the cell.
Public propertyStateGets the user interface (UI) state of the element. (Inherited from DataGridViewElement.)
Public propertyStyleGets or sets the style for the cell.
Public propertyTagGets or sets the object that contains supplemental data about the cell.
Public propertyToolTipTextGets or sets the ToolTip text associated with this cell.
Public propertyValueGets or sets the value associated with this cell.
Public propertyValueTypeGets or sets the data type of the values in the cell.
Public propertyVisibleGets a value indicating whether the cell is in a row or column that has been hidden.
Top

  NameDescription
Public methodAdjustCellBorderStyleModifies the input cell border style according to the specified criteria.
Protected methodBorderWidthsReturns a Rectangle that represents the widths of all the cell margins.
Protected methodClickUnsharesRowIndicates whether the cell's row will be unshared when the cell is clicked.
Public methodCloneCreates an exact copy of this cell.
Protected methodContentClickUnsharesRowIndicates whether the cell's row will be unshared when the cell's content is clicked.
Protected methodContentDoubleClickUnsharesRowIndicates whether the cell's row will be unshared when the cell's content is double-clicked.
Protected methodCreateAccessibilityInstanceCreates a new accessible object for the DataGridViewCell.
Public methodDetachEditingControlRemoves the cell's editing control from the DataGridView.
Public methodDispose()Releases all resources used by the DataGridViewCell.
Protected methodDispose(Boolean)Releases the unmanaged resources used by the DataGridViewCell and optionally releases the managed resources.
Protected methodDoubleClickUnsharesRowIndicates whether the cell's row will be unshared when the cell is double-clicked.
Protected methodEnterUnsharesRowIndicates whether the parent row will be unshared when the focus moves to the cell.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeReleases the unmanaged resources and performs other cleanup operations before the DataGridViewCell is reclaimed by garbage collection. (Overrides Object.Finalize().)
Protected methodGetClipboardContentRetrieves the formatted value of the cell to copy to the Clipboard.
Public methodGetContentBounds(Int32)Returns the bounding rectangle that encloses the cell's content area using a default Graphics and cell style currently in effect for the cell.
Protected methodGetContentBounds(Graphics, DataGridViewCellStyle, Int32)Returns the bounding rectangle that encloses the cell's content area, which is calculated using the specified Graphics and cell style.
Public methodGetEditedFormattedValueReturns the current, formatted value of the cell, regardless of whether the cell is in edit mode and the value has not been committed.
Protected methodGetErrorIconBoundsReturns the bounding rectangle that encloses the cell's error icon, if one is displayed.
Protected methodGetErrorTextReturns a string that represents the error for the cell.
Protected methodGetFormattedValueGets the value of the cell as formatted for display.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetInheritedContextMenuStripGets the inherited shortcut menu for the current cell.
Public methodGetInheritedStateReturns a value indicating the current state of the cell as inherited from the state of its row and column.
Public methodGetInheritedStyleGets the style applied to the cell.
Protected methodGetPreferredSizeCalculates the preferred size, in pixels, of the cell.
Protected methodGetSizeGets the size of the cell.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodGetValueGets the value of the cell.
Public methodInitializeEditingControlInitializes the control used to edit the cell.
Protected methodKeyDownUnsharesRowIndicates whether the parent row is unshared if the user presses a key while the focus is on the cell.
Public methodKeyEntersEditModeDetermines if edit mode should be started based on the given key.
Protected methodKeyPressUnsharesRowIndicates whether a row will be unshared if a key is pressed while a cell in the row has focus.
Protected methodKeyUpUnsharesRowIndicates whether the parent row is unshared when the user releases a key while the focus is on the cell.
Protected methodLeaveUnsharesRowIndicates whether a row will be unshared when the focus leaves a cell in the row.
Public methodStatic memberMeasureTextHeight(Graphics, String, Font, Int32, TextFormatFlags)Gets the height, in pixels, of the specified text, given the specified characteristics.
Public methodStatic memberMeasureTextHeight(Graphics, String, Font, Int32, TextFormatFlags, Boolean)Gets the height, in pixels, of the specified text, given the specified characteristics. Also indicates whether the required width is greater than the specified maximum width.
Public methodStatic memberMeasureTextPreferredSizeGets the ideal height and width of the specified text given the specified characteristics.
Public methodStatic memberMeasureTextSizeGets the height and width of the specified text given the specified characteristics.
Public methodStatic memberMeasureTextWidthGets the width, in pixels, of the specified text given the specified characteristics.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMouseClickUnsharesRowIndicates whether a row will be unshared if the user clicks a mouse button while the pointer is on a cell in the row.
Protected methodMouseDoubleClickUnsharesRowIndicates whether a row will be unshared if the user double-clicks a cell in the row.
Protected methodMouseDownUnsharesRowIndicates whether a row will be unshared when the user holds down a mouse button while the pointer is on a cell in the row.
Protected methodMouseEnterUnsharesRowIndicates whether a row will be unshared when the mouse pointer moves over a cell in the row.
Protected methodMouseLeaveUnsharesRowIndicates whether a row will be unshared when the mouse pointer leaves the row.
Protected methodMouseMoveUnsharesRowIndicates whether a row will be unshared when the mouse pointer moves over a cell in the row.
Protected methodMouseUpUnsharesRowIndicates whether a row will be unshared when the user releases a mouse button while the pointer is on a cell in the row.
Protected methodOnClickCalled when the cell is clicked.
Protected methodOnContentClickCalled when the cell's contents are clicked.
Protected methodOnContentDoubleClickCalled when the cell's contents are double-clicked.
Protected methodOnDataGridViewChangedCalled when the DataGridView property of the cell changes. (Overrides DataGridViewElement.OnDataGridViewChanged().)
Protected methodOnDoubleClickCalled when the cell is double-clicked.
Protected methodOnEnterCalled when the focus moves to a cell.
Protected methodOnKeyDownCalled when a character key is pressed while the focus is on a cell.
Protected methodOnKeyPressCalled when a key is pressed while the focus is on a cell.
Protected methodOnKeyUpCalled when a character key is released while the focus is on a cell.
Protected methodOnLeaveCalled when the focus moves from a cell.
Protected methodOnMouseClickCalled when the user clicks a mouse button while the pointer is on a cell.
Protected methodOnMouseDoubleClickCalled when the user double-clicks a mouse button while the pointer is on a cell.
Protected methodOnMouseDownCalled when the user holds down a mouse button while the pointer is on a cell.
Protected methodOnMouseEnterCalled when the mouse pointer moves over a cell.
Protected methodOnMouseLeaveCalled when the mouse pointer leaves the cell.
Protected methodOnMouseMoveCalled when the mouse pointer moves within a cell.
Protected methodOnMouseUpCalled when the user releases a mouse button while the pointer is on a cell.
Protected methodPaintPaints the current DataGridViewCell.
Protected methodPaintBorderPaints the border of the current DataGridViewCell.
Protected methodPaintErrorIconPaints the error icon of the current DataGridViewCell.
Public methodParseFormattedValueConverts a value formatted for display to an actual cell value.
Public methodPositionEditingControlSets the location and size of the editing control hosted by a cell in the DataGridView control.
Public methodPositionEditingPanelSets the location and size of the editing panel hosted by the cell, and returns the normal bounds of the editing control within the editing panel.
Protected methodRaiseCellClickRaises the DataGridView.CellClick event. (Inherited from DataGridViewElement.)
Protected methodRaiseCellContentClickRaises the DataGridView.CellContentClick event. (Inherited from DataGridViewElement.)
Protected methodRaiseCellContentDoubleClickRaises the DataGridView.CellContentDoubleClick event. (Inherited from DataGridViewElement.)
Protected methodRaiseCellValueChangedRaises the DataGridView.CellValueChanged event. (Inherited from DataGridViewElement.)
Protected methodRaiseDataErrorRaises the DataGridView.DataError event. (Inherited from DataGridViewElement.)
Protected methodRaiseMouseWheelRaises the Control.MouseWheel event. (Inherited from DataGridViewElement.)
Protected methodSetValueSets the value of the cell.
Public methodToStringReturns a string that describes the current object. (Overrides Object.ToString().)
Top

The DataGridViewCell class represents an individual cell in a DataGridView control. You can retrieve cells through the Cells collection of a DataGridViewRow.

The row and column for a DataGridViewCell identify the cell's location in the DataGridView. A typical cell contains data specific to the row and column in which it is contained. The cell can be customized in a number of ways by setting its properties and handling the events associated with it.

Notes to Inheritors

When you derive from DataGridViewCell and add new properties to the derived class, be sure to override the Clone method to copy the new properties during cloning operations. You should also call the base class's Clone method so that the properties of the base class are copied to the new cell.

The following code example illustrates the use of this type. For more information about this example, see How to: Add ToolTips to Individual Cells in a Windows Forms DataGridView Control.

// Sets the ToolTip text for cells in the Rating column. 
void dataGridView1_CellFormatting(object sender, 
    DataGridViewCellFormattingEventArgs e)
{
    if ( (e.ColumnIndex == this.dataGridView1.Columns["Rating"].Index)
        && e.Value != null )
    {
        DataGridViewCell cell = 
            this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
        if (e.Value.Equals("*"))
        {                
            cell.ToolTipText = "very bad";
        }
        else if (e.Value.Equals("**"))
        {
            cell.ToolTipText = "bad";
        }
        else if (e.Value.Equals("***"))
        {
            cell.ToolTipText = "good";
        }
        else if (e.Value.Equals("****"))
        {
            cell.ToolTipText = "very good";
        }
    }
}

.NET Framework

Supported in: 4.6, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft