DataGridView.CancelRowEdit Kejadian
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Terjadi ketika VirtualMode properti DataGridView kontrol adalah true
dan pembatalan diedit secara berturut-turut.
public:
event System::Windows::Forms::QuestionEventHandler ^ CancelRowEdit;
public event System.Windows.Forms.QuestionEventHandler CancelRowEdit;
public event System.Windows.Forms.QuestionEventHandler? CancelRowEdit;
member this.CancelRowEdit : System.Windows.Forms.QuestionEventHandler
Public Custom Event CancelRowEdit As QuestionEventHandler
Jenis Acara
Contoh
Contoh kode berikut menggambarkan cara menangani peristiwa ini untuk DataGridView kontrol dalam mode virtual. Saat kontrol dalam mode edit, rowInEdit
variabel menyimpan indeks baris yang sedang diedit, dan variabel menyimpan referensi ke objek Pelanggan yang sesuai dengan baris tersebut customerInEdit
. Ketika pengguna membatalkan mode edit, objek ini dapat dibuang. Namun, jika baris yang diedit pengguna adalah baris untuk rekaman baru, namun, objek Pelanggan lama dibuang dan diganti dengan yang baru sehingga pengguna dapat mulai melakukan pengeditan lagi. Contoh ini adalah bagian dari contoh yang lebih besar yang tersedia di Panduan: Menerapkan Mode Virtual di Formulir Windows DataGridView Control.
void dataGridView1_CancelRowEdit( Object^ /*sender*/,
System::Windows::Forms::QuestionEventArgs^ /*e*/ )
{
if ( this->rowInEdit == this->dataGridView1->Rows->Count - 2 &&
this->rowInEdit == this->customers->Count )
{
// If the user has canceled the edit of a newly created row,
// replace the corresponding Customer object with a new, empty one.
this->customerInEdit = gcnew Customer;
}
else
{
// If the user has canceled the edit of an existing row,
// release the corresponding Customer object.
this->customerInEdit = nullptr;
this->rowInEdit = -1;
}
}
private void dataGridView1_CancelRowEdit(object sender,
System.Windows.Forms.QuestionEventArgs e)
{
if (this.rowInEdit == this.dataGridView1.Rows.Count - 2 &&
this.rowInEdit == this.customers.Count)
{
// If the user has canceled the edit of a newly created row,
// replace the corresponding Customer object with a new, empty one.
this.customerInEdit = new Customer();
}
else
{
// If the user has canceled the edit of an existing row,
// release the corresponding Customer object.
this.customerInEdit = null;
this.rowInEdit = -1;
}
}
Private Sub dataGridView1_CancelRowEdit(ByVal sender As Object, _
ByVal e As System.Windows.Forms.QuestionEventArgs) _
Handles dataGridView1.CancelRowEdit
If Me.rowInEdit = Me.dataGridView1.Rows.Count - 2 AndAlso _
Me.rowInEdit = Me.customers.Count Then
' If the user has canceled the edit of a newly created row,
' replace the corresponding Customer object with a new, empty one.
Me.customerInEdit = New Customer()
Else
' If the user has canceled the edit of an existing row,
' release the corresponding Customer object.
Me.customerInEdit = Nothing
Me.rowInEdit = -1
End If
End Sub
Keterangan
DataGridView Saat berada dalam mode virtual, perubahan diterapkan pada cache data di tingkat sel secara default. Peristiwa CancelRowEdit dapat digunakan saat menerapkan transaksi tingkat baris.
Untuk informasi selengkapnya tentang cara menangani peristiwa, lihat Menangani dan Menaikkan Peristiwa.
Berlaku untuk
Lihat juga
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk