Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
InvalidateCell Method (DataGridViewCell)
Collapse the table of content
Expand the table of content

DataGridView.InvalidateCell Method (DataGridViewCell)

Note: This method is new in the .NET Framework version 2.0.

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
public void InvalidateCell (
	DataGridViewCell dataGridViewCell
public function InvalidateCell (
	dataGridViewCell : DataGridViewCell



The DataGridViewCell to invalidate.

Exception typeCondition


dataGridViewCell does not belong to the DataGridView.


dataGridViewCell is a null reference (Nothing in Visual Basic).

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)

// Force the cell to repaint itself when the mouse pointer leaves it.
protected override void OnMouseLeave(int rowIndex)

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

© 2015 Microsoft