0 out of 2 rated this helpful - Rate this topic

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.

  Name Description
Protected method DataGridViewCell Initializes a new instance of the DataGridViewCell class.
Top
  Name Description
Public property AccessibilityObject Gets the DataGridViewCell.DataGridViewCellAccessibleObject assigned to the DataGridViewCell.
Public property ColumnIndex Gets the column index for this cell.
Public property ContentBounds Gets the bounding rectangle that encloses the cell's content area.
Public property ContextMenuStrip Gets or sets the shortcut menu associated with the cell.
Public property DataGridView Gets the DataGridView control associated with this element. (Inherited from DataGridViewElement.)
Public property DefaultNewRowValue Gets the default value for a cell in the row for new records.
Public property Displayed Gets a value that indicates whether the cell is currently displayed on-screen.
Public property EditedFormattedValue Gets the current, formatted value of the cell, regardless of whether the cell is in edit mode and the value has not been committed.
Public property EditType Gets the type of the cell's hosted editing control.
Public property ErrorIconBounds Gets the bounds of the error icon for the cell.
Public property ErrorText Gets or sets the text describing an error condition associated with the cell.
Public property FormattedValue Gets the value of the cell as formatted for display.
Public property FormattedValueType Gets the type of the formatted value associated with the cell.
Public property Frozen Gets a value indicating whether the cell is frozen.
Public property HasStyle Gets a value indicating whether the Style property has been set.
Public property InheritedState Gets the current state of the cell as inherited from the state of its row and column.
Public property InheritedStyle Gets the style currently applied to the cell.
Public property IsInEditMode Gets a value indicating whether this cell is currently being edited.
Public property OwningColumn Gets the column that contains this cell.
Public property OwningRow Gets the row that contains this cell.
Public property PreferredSize Gets the size, in pixels, of a rectangular area into which the cell can fit.
Public property ReadOnly Gets or sets a value indicating whether the cell's data can be edited.
Public property Resizable Gets a value indicating whether the cell can be resized.
Public property RowIndex Gets the index of the cell's parent row.
Public property Selected Gets or sets a value indicating whether the cell has been selected.
Public property Size Gets the size of the cell.
Public property State Gets the user interface (UI) state of the element. (Inherited from DataGridViewElement.)
Public property Style Gets or sets the style for the cell.
Public property Tag Gets or sets the object that contains supplemental data about the cell.
Public property ToolTipText Gets or sets the ToolTip text associated with this cell.
Public property Value Gets or sets the value associated with this cell.
Public property ValueType Gets or sets the data type of the values in the cell.
Public property Visible Gets a value indicating whether the cell is in a row or column that has been hidden.
Top
  Name Description
Public method AdjustCellBorderStyle Modifies the input cell border style according to the specified criteria.
Protected method BorderWidths Returns a Rectangle that represents the widths of all the cell margins.
Protected method ClickUnsharesRow Indicates whether the cell's row will be unshared when the cell is clicked.
Public method Clone Creates an exact copy of this cell.
Protected method ContentClickUnsharesRow Indicates whether the cell's row will be unshared when the cell's content is clicked.
Protected method ContentDoubleClickUnsharesRow Indicates whether the cell's row will be unshared when the cell's content is double-clicked.
Protected method CreateAccessibilityInstance Creates a new accessible object for the DataGridViewCell.
Public method DetachEditingControl Removes the cell's editing control from the DataGridView.
Public method Dispose() Releases all resources used by the DataGridViewCell.
Protected method Dispose(Boolean) Releases the unmanaged resources used by the DataGridViewCell and optionally releases the managed resources.
Protected method DoubleClickUnsharesRow Indicates whether the cell's row will be unshared when the cell is double-clicked.
Protected method EnterUnsharesRow Indicates whether the parent row will be unshared when the focus moves to the cell.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Releases the unmanaged resources and performs other cleanup operations before the DataGridViewCell is reclaimed by garbage collection. (Overrides Object.Finalize().)
Protected method GetClipboardContent Retrieves the formatted value of the cell to copy to the Clipboard.
Public method GetContentBounds(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 method GetContentBounds(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 method GetEditedFormattedValue Returns the current, formatted value of the cell, regardless of whether the cell is in edit mode and the value has not been committed.
Protected method GetErrorIconBounds Returns the bounding rectangle that encloses the cell's error icon, if one is displayed.
Protected method GetErrorText Returns a string that represents the error for the cell.
Protected method GetFormattedValue Gets the value of the cell as formatted for display.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetInheritedContextMenuStrip Gets the inherited shortcut menu for the current cell.
Public method GetInheritedState Returns a value indicating the current state of the cell as inherited from the state of its row and column.
Public method GetInheritedStyle Gets the style applied to the cell.
Protected method GetPreferredSize Calculates the preferred size, in pixels, of the cell.
Protected method GetSize Gets the size of the cell.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method GetValue Gets the value of the cell.
Public method InitializeEditingControl Initializes the control used to edit the cell.
Protected method KeyDownUnsharesRow Indicates whether the parent row is unshared if the user presses a key while the focus is on the cell.
Public method KeyEntersEditMode Determines if edit mode should be started based on the given key.
Protected method KeyPressUnsharesRow Indicates whether a row will be unshared if a key is pressed while a cell in the row has focus.
Protected method KeyUpUnsharesRow Indicates whether the parent row is unshared when the user releases a key while the focus is on the cell.
Protected method LeaveUnsharesRow Indicates whether a row will be unshared when the focus leaves a cell in the row.
Public method Static member MeasureTextHeight(Graphics, String, Font, Int32, TextFormatFlags) Gets the height, in pixels, of the specified text, given the specified characteristics.
Public method Static member MeasureTextHeight(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 method Static member MeasureTextPreferredSize Gets the ideal height and width of the specified text given the specified characteristics.
Public method Static member MeasureTextSize Gets the height and width of the specified text given the specified characteristics.
Public method Static member MeasureTextWidth Gets the width, in pixels, of the specified text given the specified characteristics.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MouseClickUnsharesRow Indicates whether a row will be unshared if the user clicks a mouse button while the pointer is on a cell in the row.
Protected method MouseDoubleClickUnsharesRow Indicates whether a row will be unshared if the user double-clicks a cell in the row.
Protected method MouseDownUnsharesRow 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.
Protected method MouseEnterUnsharesRow Indicates whether a row will be unshared when the mouse pointer moves over a cell in the row.
Protected method MouseLeaveUnsharesRow Indicates whether a row will be unshared when the mouse pointer leaves the row.
Protected method MouseMoveUnsharesRow Indicates whether a row will be unshared when the mouse pointer moves over a cell in the row.
Protected method MouseUpUnsharesRow Indicates whether a row will be unshared when the user releases a mouse button while the pointer is on a cell in the row.
Protected method OnClick Called when the cell is clicked.
Protected method OnContentClick Called when the cell's contents are clicked.
Protected method OnContentDoubleClick Called when the cell's contents are double-clicked.
Protected method OnDataGridViewChanged Called when the DataGridView property of the cell changes. (Overrides DataGridViewElement.OnDataGridViewChanged().)
Protected method OnDoubleClick Called when the cell is double-clicked.
Protected method OnEnter Called when the focus moves to a cell.
Protected method OnKeyDown Called when a character key is pressed while the focus is on a cell.
Protected method OnKeyPress Called when a key is pressed while the focus is on a cell.
Protected method OnKeyUp Called when a character key is released while the focus is on a cell.
Protected method OnLeave Called when the focus moves from a cell.
Protected method OnMouseClick Called when the user clicks a mouse button while the pointer is on a cell.
Protected method OnMouseDoubleClick Called when the user double-clicks a mouse button while the pointer is on a cell.
Protected method OnMouseDown Called when the user holds down a mouse button while the pointer is on a cell.
Protected method OnMouseEnter Called when the mouse pointer moves over a cell.
Protected method OnMouseLeave Called when the mouse pointer leaves the cell.
Protected method OnMouseMove Called when the mouse pointer moves within a cell.
Protected method OnMouseUp Called when the user releases a mouse button while the pointer is on a cell.
Protected method Paint Paints the current DataGridViewCell.
Protected method PaintBorder Paints the border of the current DataGridViewCell.
Protected method PaintErrorIcon Paints the error icon of the current DataGridViewCell.
Public method ParseFormattedValue Converts a value formatted for display to an actual cell value.
Public method PositionEditingControl Sets the location and size of the editing control hosted by a cell in the DataGridView control.
Public method PositionEditingPanel 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.
Protected method RaiseCellClick Raises the DataGridView.CellClick event. (Inherited from DataGridViewElement.)
Protected method RaiseCellContentClick Raises the DataGridView.CellContentClick event. (Inherited from DataGridViewElement.)
Protected method RaiseCellContentDoubleClick Raises the DataGridView.CellContentDoubleClick event. (Inherited from DataGridViewElement.)
Protected method RaiseCellValueChanged Raises the DataGridView.CellValueChanged event. (Inherited from DataGridViewElement.)
Protected method RaiseDataError Raises the DataGridView.DataError event. (Inherited from DataGridViewElement.)
Protected method RaiseMouseWheel Raises the Control.MouseWheel event. (Inherited from DataGridViewElement.)
Protected method SetValue Sets the value of the cell.
Public method ToString Returns 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, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ