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

注釈

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

塗りつぶしと無効化の詳細については、「 Invalidate」を参照してください。

適用対象

こちらもご覧ください