Export (0) Print
Expand All

DataGridView.InvalidateCell Method (DataGridViewCell)

Invalidates the specified cell of the DataGridView, forcing it to be repainted.

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

public void InvalidateCell(
	DataGridViewCell dataGridViewCell
)

Parameters

dataGridViewCell
Type: System.Windows.Forms.DataGridViewCell
The DataGridViewCell to invalidate.

ExceptionCondition
ArgumentException

dataGridViewCell does not belong to the DataGridView.

ArgumentNullException

dataGridViewCell is null.

This method is useful to force a cell repaint in conditions that would not normally cause a cell to be repainted. For example, you can use this method with a custom cell type that changes its appearance as a result of external events.

For more information about painting and invalidation, see Invalidate.

The following code example illustrates how to use this method in a customized DataGridViewCell that is painted with a custom border when the mouse pointer rests on it. In the example, the cell is invalidated when the mouse pointer enters or leaves it.

This code is part of a larger example available in How to: Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance.


// Force the cell to repaint itself when the mouse pointer enters it.
protected override void OnMouseEnter(int rowIndex)
{
    this.DataGridView.InvalidateCell(this);
}

// Force the cell to repaint itself when the mouse pointer leaves it.
protected override void OnMouseLeave(int rowIndex)
{
    this.DataGridView.InvalidateCell(this);
}


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

Community Additions

ADD
Show:
© 2014 Microsoft