Bagikan melalui


DataGridView.CurrentCellAddress Properti

Definisi

Mendapatkan indeks baris dan kolom dari sel yang saat ini aktif.

public:
 property System::Drawing::Point CurrentCellAddress { System::Drawing::Point get(); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Point CurrentCellAddress { get; }
[<System.ComponentModel.Browsable(false)>]
member this.CurrentCellAddress : System.Drawing.Point
Public ReadOnly Property CurrentCellAddress As Point

Nilai Properti

Point yang mewakili indeks baris dan kolom dari sel yang saat ini aktif.

Atribut

Contoh

Contoh kode berikut menggambarkan cara menggunakan CurrentCellAddress properti dalam skenario lukisan baris. Dalam contoh, properti ini digunakan untuk menyimpan indeks baris sel saat ini. Ketika pengguna mengubah sel saat ini ke baris yang berbeda, baris dipaksa untuk mengecat ulang dirinya sendiri.

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

Keterangan

Gunakan properti ini untuk menentukan baris dan kolom sel saat ini tanpa mengakses sel secara langsung. Ini berguna untuk menghindari pembukaan baris bersama. Untuk informasi selengkapnya tentang berbagi baris, lihat Praktik Terbaik untuk Menskalakan kontrol Formulir Windows DataGridView.

Berlaku untuk

Lihat juga