DataGridViewCell Class
TOC
Collapse the table of content
Expand the table of content

DataGridViewCell Class

 

Represents an individual cell in a DataGridView control.

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


Public MustInherit Class DataGridViewCell
	Inherits DataGridViewElement
	Implements ICloneable, IDisposable

NameDescription
System_CAPS_protmethodDataGridViewCell()

Initializes a new instance of the DataGridViewCell class.

NameDescription
System_CAPS_pubpropertyAccessibilityObject

Gets the DataGridViewCell.DataGridViewCellAccessibleObject assigned to the DataGridViewCell.

System_CAPS_pubpropertyColumnIndex

Gets the column index for this cell.

System_CAPS_pubpropertyContentBounds

Gets the bounding rectangle that encloses the cell's content area.

System_CAPS_pubpropertyContextMenuStrip

Gets or sets the shortcut menu associated with the cell.

System_CAPS_pubpropertyDataGridView

Gets the DataGridView control associated with this element.(Inherited from DataGridViewElement.)

System_CAPS_pubpropertyDefaultNewRowValue

Gets the default value for a cell in the row for new records.

System_CAPS_pubpropertyDisplayed

Gets a value that indicates whether the cell is currently displayed on-screen.

System_CAPS_pubpropertyEditedFormattedValue

Gets the current, formatted value of the cell, regardless of whether the cell is in edit mode and the value has not been committed.

System_CAPS_pubpropertyEditType

Gets the type of the cell's hosted editing control.

System_CAPS_pubpropertyErrorIconBounds

Gets the bounds of the error icon for the cell.

System_CAPS_pubpropertyErrorText

Gets or sets the text describing an error condition associated with the cell.

System_CAPS_pubpropertyFormattedValue

Gets the value of the cell as formatted for display.

System_CAPS_pubpropertyFormattedValueType

Gets the type of the formatted value associated with the cell.

System_CAPS_pubpropertyFrozen

Gets a value indicating whether the cell is frozen.

System_CAPS_pubpropertyHasStyle

Gets a value indicating whether the Style property has been set.

System_CAPS_pubpropertyInheritedState

Gets the current state of the cell as inherited from the state of its row and column.

System_CAPS_pubpropertyInheritedStyle

Gets the style currently applied to the cell.

System_CAPS_pubpropertyIsInEditMode

Gets a value indicating whether this cell is currently being edited.

System_CAPS_pubpropertyOwningColumn

Gets the column that contains this cell.

System_CAPS_pubpropertyOwningRow

Gets the row that contains this cell.

System_CAPS_pubpropertyPreferredSize

Gets the size, in pixels, of a rectangular area into which the cell can fit.

System_CAPS_pubpropertyReadOnly

Gets or sets a value indicating whether the cell's data can be edited.

System_CAPS_pubpropertyResizable

Gets a value indicating whether the cell can be resized.

System_CAPS_pubpropertyRowIndex

Gets the index of the cell's parent row.

System_CAPS_pubpropertySelected

Gets or sets a value indicating whether the cell has been selected.

System_CAPS_pubpropertySize

Gets the size of the cell.

System_CAPS_pubpropertyState

Gets the user interface (UI) state of the element.(Inherited from DataGridViewElement.)

System_CAPS_pubpropertyStyle

Gets or sets the style for the cell.

System_CAPS_pubpropertyTag

Gets or sets the object that contains supplemental data about the cell.

System_CAPS_pubpropertyToolTipText

Gets or sets the ToolTip text associated with this cell.

System_CAPS_pubpropertyValue

Gets or sets the value associated with this cell.

System_CAPS_pubpropertyValueType

Gets or sets the data type of the values in the cell.

System_CAPS_pubpropertyVisible

Gets a value indicating whether the cell is in a row or column that has been hidden.

NameDescription
System_CAPS_pubmethodAdjustCellBorderStyle(DataGridViewAdvancedBorderStyle, DataGridViewAdvancedBorderStyle, Boolean, Boolean, Boolean, Boolean)

Modifies the input cell border style according to the specified criteria.

System_CAPS_protmethodBorderWidths(DataGridViewAdvancedBorderStyle)

Returns a Rectangle that represents the widths of all the cell margins.

System_CAPS_protmethodClickUnsharesRow(DataGridViewCellEventArgs)

Indicates whether the cell's row will be unshared when the cell is clicked.

System_CAPS_pubmethodClone()

Creates an exact copy of this cell.

System_CAPS_protmethodContentClickUnsharesRow(DataGridViewCellEventArgs)

Indicates whether the cell's row will be unshared when the cell's content is clicked.

System_CAPS_protmethodContentDoubleClickUnsharesRow(DataGridViewCellEventArgs)

Indicates whether the cell's row will be unshared when the cell's content is double-clicked.

System_CAPS_protmethodCreateAccessibilityInstance()

Creates a new accessible object for the DataGridViewCell.

System_CAPS_pubmethodDetachEditingControl()

Removes the cell's editing control from the DataGridView.

System_CAPS_pubmethodDispose()

Releases all resources used by the DataGridViewCell.

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the DataGridViewCell and optionally releases the managed resources.

System_CAPS_protmethodDoubleClickUnsharesRow(DataGridViewCellEventArgs)

Indicates whether the cell's row will be unshared when the cell is double-clicked.

System_CAPS_protmethodEnterUnsharesRow(Int32, Boolean)

Indicates whether the parent row will be unshared when the focus moves to the cell.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Releases the unmanaged resources and performs other cleanup operations before the DataGridViewCell is reclaimed by garbage collection.(Overrides Object.Finalize().)

System_CAPS_protmethodGetClipboardContent(Int32, Boolean, Boolean, Boolean, Boolean, String)

Retrieves the formatted value of the cell to copy to the Clipboard.

System_CAPS_protmethodGetContentBounds(Graphics, DataGridViewCellStyle, Int32)

Returns the bounding rectangle that encloses the cell's content area, which is calculated using the specified Graphics and cell style.

System_CAPS_pubmethodGetContentBounds(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.

System_CAPS_pubmethodGetEditedFormattedValue(Int32, DataGridViewDataErrorContexts)

Returns the current, formatted value of the cell, regardless of whether the cell is in edit mode and the value has not been committed.

System_CAPS_protmethodGetErrorIconBounds(Graphics, DataGridViewCellStyle, Int32)

Returns the bounding rectangle that encloses the cell's error icon, if one is displayed.

System_CAPS_protmethodGetErrorText(Int32)

Returns a string that represents the error for the cell.

System_CAPS_protmethodGetFormattedValue(Object, Int32, DataGridViewCellStyle, TypeConverter, TypeConverter, DataGridViewDataErrorContexts)

Gets the value of the cell as formatted for display.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetInheritedContextMenuStrip(Int32)

Gets the inherited shortcut menu for the current cell.

System_CAPS_pubmethodGetInheritedState(Int32)

Returns a value indicating the current state of the cell as inherited from the state of its row and column.

System_CAPS_pubmethodGetInheritedStyle(DataGridViewCellStyle, Int32, Boolean)

Gets the style applied to the cell.

System_CAPS_protmethodGetPreferredSize(Graphics, DataGridViewCellStyle, Int32, Size)

Calculates the preferred size, in pixels, of the cell.

System_CAPS_protmethodGetSize(Int32)

Gets the size of the cell.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodGetValue(Int32)

Gets the value of the cell.

System_CAPS_pubmethodInitializeEditingControl(Int32, Object, DataGridViewCellStyle)

Initializes the control used to edit the cell.

System_CAPS_protmethodKeyDownUnsharesRow(KeyEventArgs, Int32)

Indicates whether the parent row is unshared if the user presses a key while the focus is on the cell.

System_CAPS_pubmethodKeyEntersEditMode(KeyEventArgs)

Determines if edit mode should be started based on the given key.

System_CAPS_protmethodKeyPressUnsharesRow(KeyPressEventArgs, Int32)

Indicates whether a row will be unshared if a key is pressed while a cell in the row has focus.

System_CAPS_protmethodKeyUpUnsharesRow(KeyEventArgs, Int32)

Indicates whether the parent row is unshared when the user releases a key while the focus is on the cell.

System_CAPS_protmethodLeaveUnsharesRow(Int32, Boolean)

Indicates whether a row will be unshared when the focus leaves a cell in the row.

System_CAPS_pubmethodSystem_CAPS_staticMeasureTextHeight(Graphics, String, Font, Int32, TextFormatFlags)

Gets the height, in pixels, of the specified text, given the specified characteristics.

System_CAPS_pubmethodSystem_CAPS_staticMeasureTextHeight(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.

System_CAPS_pubmethodSystem_CAPS_staticMeasureTextPreferredSize(Graphics, String, Font, Single, TextFormatFlags)

Gets the ideal height and width of the specified text given the specified characteristics.

System_CAPS_pubmethodSystem_CAPS_staticMeasureTextSize(Graphics, String, Font, TextFormatFlags)

Gets the height and width of the specified text given the specified characteristics.

System_CAPS_pubmethodSystem_CAPS_staticMeasureTextWidth(Graphics, String, Font, Int32, TextFormatFlags)

Gets the width, in pixels, of the specified text given the specified characteristics.

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodMouseClickUnsharesRow(DataGridViewCellMouseEventArgs)

Indicates whether a row will be unshared if the user clicks a mouse button while the pointer is on a cell in the row.

System_CAPS_protmethodMouseDoubleClickUnsharesRow(DataGridViewCellMouseEventArgs)

Indicates whether a row will be unshared if the user double-clicks a cell in the row.

System_CAPS_protmethodMouseDownUnsharesRow(DataGridViewCellMouseEventArgs)

Indicates whether a row will be unshared when the user holds down a mouse button while the pointer is on a cell in the row.

System_CAPS_protmethodMouseEnterUnsharesRow(Int32)

Indicates whether a row will be unshared when the mouse pointer moves over a cell in the row.

System_CAPS_protmethodMouseLeaveUnsharesRow(Int32)

Indicates whether a row will be unshared when the mouse pointer leaves the row.

System_CAPS_protmethodMouseMoveUnsharesRow(DataGridViewCellMouseEventArgs)

Indicates whether a row will be unshared when the mouse pointer moves over a cell in the row.

System_CAPS_protmethodMouseUpUnsharesRow(DataGridViewCellMouseEventArgs)

Indicates whether a row will be unshared when the user releases a mouse button while the pointer is on a cell in the row.

System_CAPS_protmethodOnClick(DataGridViewCellEventArgs)

Called when the cell is clicked.

System_CAPS_protmethodOnContentClick(DataGridViewCellEventArgs)

Called when the cell's contents are clicked.

System_CAPS_protmethodOnContentDoubleClick(DataGridViewCellEventArgs)

Called when the cell's contents are double-clicked.

System_CAPS_protmethodOnDataGridViewChanged()

Called when the DataGridView property of the cell changes.(Overrides DataGridViewElement.OnDataGridViewChanged().)

System_CAPS_protmethodOnDoubleClick(DataGridViewCellEventArgs)

Called when the cell is double-clicked.

System_CAPS_protmethodOnEnter(Int32, Boolean)

Called when the focus moves to a cell.

System_CAPS_protmethodOnKeyDown(KeyEventArgs, Int32)

Called when a character key is pressed while the focus is on a cell.

System_CAPS_protmethodOnKeyPress(KeyPressEventArgs, Int32)

Called when a key is pressed while the focus is on a cell.

System_CAPS_protmethodOnKeyUp(KeyEventArgs, Int32)

Called when a character key is released while the focus is on a cell.

System_CAPS_protmethodOnLeave(Int32, Boolean)

Called when the focus moves from a cell.

System_CAPS_protmethodOnMouseClick(DataGridViewCellMouseEventArgs)

Called when the user clicks a mouse button while the pointer is on a cell.

System_CAPS_protmethodOnMouseDoubleClick(DataGridViewCellMouseEventArgs)

Called when the user double-clicks a mouse button while the pointer is on a cell.

System_CAPS_protmethodOnMouseDown(DataGridViewCellMouseEventArgs)

Called when the user holds down a mouse button while the pointer is on a cell.

System_CAPS_protmethodOnMouseEnter(Int32)

Called when the mouse pointer moves over a cell.

System_CAPS_protmethodOnMouseLeave(Int32)

Called when the mouse pointer leaves the cell.

System_CAPS_protmethodOnMouseMove(DataGridViewCellMouseEventArgs)

Called when the mouse pointer moves within a cell.

System_CAPS_protmethodOnMouseUp(DataGridViewCellMouseEventArgs)

Called when the user releases a mouse button while the pointer is on a cell.

System_CAPS_protmethodPaint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts)

Paints the current DataGridViewCell.

System_CAPS_protmethodPaintBorder(Graphics, Rectangle, Rectangle, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle)

Paints the border of the current DataGridViewCell.

System_CAPS_protmethodPaintErrorIcon(Graphics, Rectangle, Rectangle, String)

Paints the error icon of the current DataGridViewCell.

System_CAPS_pubmethodParseFormattedValue(Object, DataGridViewCellStyle, TypeConverter, TypeConverter)

Converts a value formatted for display to an actual cell value.

System_CAPS_pubmethodPositionEditingControl(Boolean, Boolean, Rectangle, Rectangle, DataGridViewCellStyle, Boolean, Boolean, Boolean, Boolean)

Sets the location and size of the editing control hosted by a cell in the DataGridView control.

System_CAPS_pubmethodPositionEditingPanel(Rectangle, Rectangle, DataGridViewCellStyle, Boolean, Boolean, Boolean, Boolean)

Sets 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.

System_CAPS_protmethodRaiseCellClick(DataGridViewCellEventArgs)

Raises the DataGridView.CellClick event. (Inherited from DataGridViewElement.)

System_CAPS_protmethodRaiseCellContentClick(DataGridViewCellEventArgs)

Raises the DataGridView.CellContentClick event. (Inherited from DataGridViewElement.)

System_CAPS_protmethodRaiseCellContentDoubleClick(DataGridViewCellEventArgs)

Raises the DataGridView.CellContentDoubleClick event. (Inherited from DataGridViewElement.)

System_CAPS_protmethodRaiseCellValueChanged(DataGridViewCellEventArgs)

Raises the DataGridView.CellValueChanged event. (Inherited from DataGridViewElement.)

System_CAPS_protmethodRaiseDataError(DataGridViewDataErrorEventArgs)

Raises the DataGridView.DataError event. (Inherited from DataGridViewElement.)

System_CAPS_protmethodRaiseMouseWheel(MouseEventArgs)

Raises the Control.MouseWheel event. (Inherited from DataGridViewElement.)

System_CAPS_protmethodSetValue(Int32, Object)

Sets the value of the cell.

System_CAPS_pubmethodToString()

Returns a string that describes the current object. (Overrides Object.ToString().)

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.
Sub dataGridView1_CellFormatting(ByVal sender As Object, _
    ByVal e As DataGridViewCellFormattingEventArgs) _
    Handles dataGridView1.CellFormatting

    If e.ColumnIndex = Me.dataGridView1.Columns("Rating").Index _
        AndAlso (e.Value IsNot Nothing) Then

        With Me.dataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)

            If e.Value.Equals("*") Then
                .ToolTipText = "very bad"
            ElseIf e.Value.Equals("**") Then
                .ToolTipText = "bad"
            ElseIf e.Value.Equals("***") Then
                .ToolTipText = "good"
            ElseIf e.Value.Equals("****") Then
                .ToolTipText = "very good"
            End If

        End With

    End If

End Sub 'dataGridView1_CellFormatting

.NET Framework
Available since 2.0

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

Return to top
Show:
© 2016 Microsoft