Bagikan melalui


DataGridView.InvalidateRow(Int32) Metode

Definisi

Membatalkan baris yang ditentukan dari DataGridView, memaksanya untuk dicat ulang.

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

Parameter

rowIndex
Int32

Indeks baris yang akan dibatalkan.

Pengecualian

rowIndex tidak dalam rentang valid 0 hingga jumlah baris dikurangi 1.

Contoh

Contoh kode berikut menggambarkan cara menggunakan InvalidateRow metode dalam skenario lukisan baris. Dalam contoh, baris tidak valid ketika sel saat ini berubah, memaksa baris untuk mengecat ulang dirinya sendiri.

Kode ini adalah bagian dari contoh yang lebih besar yang tersedia di Cara: Menyesuaikan Tampilan Baris di kontrol Formulir 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

Keterangan

Gunakan metode ini untuk memaksa baris untuk mengecat ulang dirinya sendiri. Metode ini berguna dalam skenario gambar pemilik tempat Anda menangani RowPrePaintRowPostPaint atau peristiwa.

Untuk informasi selengkapnya tentang pengecatan dan pembatalan, lihat Invalidate.

Berlaku untuk

Lihat juga