DataGridView.InvalidateRow(Int32) メソッド

定義

DataGridView の指定された行を無効化して、強制的に再描画します。

public:
 void InvalidateRow(int rowIndex);
public void InvalidateRow (int rowIndex);
member this.InvalidateRow : int -> unit
Public Sub InvalidateRow (rowIndex As Integer)

パラメーター

rowIndex
Int32

無効化する行のインデックス。

例外

rowIndex が、0 以上、行数 - 1 以下の、有効な範囲内にありません。

次のコード例は、行描画シナリオで メソッドを InvalidateRow 使用する方法を示しています。 この例では、現在のセルが変更されると行が無効になり、行が強制的に再描画されます。

このコードは、「方法: Windows フォーム DataGridView コントロールの行の外観をカスタマイズする」で使用できるより大きな例の一部です。

// Forces the row to repaint itself when the user changes the 
// current cell. This is necessary to refresh the focus rectangle.
void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
    if (oldRowIndex != -1)
    {
        this.dataGridView1.InvalidateRow(oldRowIndex);
    }
    oldRowIndex = this.dataGridView1.CurrentCellAddress.Y;
}
' Forces the row to repaint itself when the user changes the 
' current cell. This is necessary to refresh the focus rectangle.
Sub dataGridView1_CurrentCellChanged(ByVal sender As Object, _
    ByVal e As EventArgs) Handles dataGridView1.CurrentCellChanged

    If oldRowIndex <> -1 Then
        Me.dataGridView1.InvalidateRow(oldRowIndex)
    End If
    oldRowIndex = Me.dataGridView1.CurrentCellAddress.Y

End Sub

注釈

行を強制的に再描画するには、このメソッドを使用します。 このメソッドは、 または RowPostPaint イベントを処理RowPrePaintする所有者描画シナリオで役立ちます。

描画と無効化の詳細については、「」を参照してください Invalidate

適用対象

こちらもご覧ください