DataGridView.InvalidateCell Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Invalidates a cell in the DataGridView, forcing it to be repainted.
Overloads
InvalidateCell(DataGridViewCell) |
Invalidates the specified cell of the DataGridView, forcing it to be repainted. |
InvalidateCell(Int32, Int32) |
Invalidates the cell with the specified row and column indexes, forcing it to be repainted. |
InvalidateCell(DataGridViewCell)
- Source:
- DataGridView.Methods.cs
- Source:
- DataGridView.Methods.cs
- Source:
- DataGridView.Methods.cs
Invalidates the specified cell of the DataGridView, forcing it to be repainted.
public:
void InvalidateCell(System::Windows::Forms::DataGridViewCell ^ dataGridViewCell);
public void InvalidateCell (System.Windows.Forms.DataGridViewCell dataGridViewCell);
member this.InvalidateCell : System.Windows.Forms.DataGridViewCell -> unit
Public Sub InvalidateCell (dataGridViewCell As DataGridViewCell)
Parameters
- dataGridViewCell
- DataGridViewCell
The DataGridViewCell to invalidate.
Exceptions
dataGridViewCell
does not belong to the DataGridView.
dataGridViewCell
is null
.
Examples
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);
}
' Force the cell to repaint itself when the mouse pointer enters it.
Protected Overrides Sub OnMouseEnter(ByVal rowIndex As Integer)
Me.DataGridView.InvalidateCell(Me)
End Sub
' Force the cell to repaint itself when the mouse pointer leaves it.
Protected Overrides Sub OnMouseLeave(ByVal rowIndex As Integer)
Me.DataGridView.InvalidateCell(Me)
End Sub
Remarks
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.
See also
Applies to
InvalidateCell(Int32, Int32)
- Source:
- DataGridView.Methods.cs
- Source:
- DataGridView.Methods.cs
- Source:
- DataGridView.Methods.cs
Invalidates the cell with the specified row and column indexes, forcing it to be repainted.
public:
void InvalidateCell(int columnIndex, int rowIndex);
public void InvalidateCell (int columnIndex, int rowIndex);
member this.InvalidateCell : int * int -> unit
Public Sub InvalidateCell (columnIndex As Integer, rowIndex As Integer)
Parameters
- columnIndex
- Int32
The column index of the cell to invalidate.
- rowIndex
- Int32
The row index of the cell to invalidate.
Exceptions
columnIndex
is less than -1 or greater than the number of columns in the control minus 1.
-or-
rowIndex
is less than -1 or greater than the number of rows in the control minus 1.
Examples
The following code example illustrates how to use this method in a custom cell type that changes a cell's appearance when the user rests the mouse pointer over it. This example 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);
}
' Force the cell to repaint itself when the mouse pointer enters it.
Protected Overrides Sub OnMouseEnter(ByVal rowIndex As Integer)
Me.DataGridView.InvalidateCell(Me)
End Sub
' Force the cell to repaint itself when the mouse pointer leaves it.
Protected Overrides Sub OnMouseLeave(ByVal rowIndex As Integer)
Me.DataGridView.InvalidateCell(Me)
End Sub
Remarks
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.