DataGridView.InvalidateRow(Int32) Metoda

Definicja

Unieważnia określony wiersz elementu DataGridView, zmuszając go do przemalowania.

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

Parametry

rowIndex
Int32

Indeks wiersza do unieważnienia.

Wyjątki

rowIndex nie znajduje się w prawidłowym zakresie od 0 do liczby wierszy minus 1.

Przykłady

Poniższy przykład kodu ilustruje sposób użycia InvalidateRow metody w scenariuszu malowania wierszy. W tym przykładzie wiersz jest unieważniany, gdy bieżąca komórka ulegnie zmianie, zmuszając wiersz do ponownego zamazania.

Ten kod jest częścią większego przykładu dostępnego w temacie How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control (Dostosowywanie wyglądu wierszy w kontrolce 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

Uwagi

Użyj tej metody, aby wymusić powtórzenie wiersza. Ta metoda jest przydatna w scenariuszach rysowania właścicieli, w których są obsługiwane RowPrePaint zdarzenia lub RowPostPaint .

Aby uzyskać więcej informacji na temat malowania i unieważniania, zobacz Invalidate.

Dotyczy

Zobacz też