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 方法。 在此範例中,當目前儲存格變更時,資料列會失效,強制重新繪製資料列本身。

此程式碼是How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control中較大範例的一部分。

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

備註

使用這個方法來強制資料列重新繪製本身。 此方法在處理 RowPrePaintRowPostPaint 事件的擁有者繪圖案例中很有用。

如需繪製和失效的詳細資訊,請參閱 Invalidate

適用於

另請參閱