Bagikan melalui


ListViewInsertedEventArgs.KeepInInsertMode Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah nilai input pengguna dipertahankan untuk kontrol di InsertItemTemplate dalam templat.

public:
 property bool KeepInInsertMode { bool get(); void set(bool value); };
public bool KeepInInsertMode { get; set; }
member this.KeepInInsertMode : bool with get, set
Public Property KeepInInsertMode As Boolean

Nilai Properti

true jika nilai input pengguna dipertahankan untuk kontrol di dalam InsertItemTemplate templat; false jika nilai input pengguna diganti dengan nilai default untuk kontrol. Default adalah false.

Contoh

Contoh berikut menunjukkan cara menggunakan KeepInInsertMode properti untuk mempertahankan nilai yang dimasukkan oleh pengguna saat kesalahan terjadi selama operasi penyisipan. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ListViewInsertedEventArgs kelas .

void ContactsListView_ItemInserted(Object sender, ListViewInsertedEventArgs e)
{
  if (e.Exception != null)
  {
    if (e.AffectedRows == 0)
    {
      e.KeepInInsertMode = true;
      Message.Text = "An exception occurred inserting the new Contact. " +
        "Please verify your values and try again.";
    }
    else
      Message.Text = "An exception occurred inserting the new Contact. " +
        "Please verify the values in the newly inserted item.";

    e.ExceptionHandled = true;
  }
}
Sub ContactsListView_ItemInserted(ByVal sender As Object, ByVal e As ListViewInsertedEventArgs)

  If e.Exception IsNot Nothing Then

    If e.AffectedRows = 0 Then
      e.KeepInInsertMode = True
      Message.Text = "An exception occurred inserting the new Contact. " & _
        "Please verify your values and try again."
    Else
      Message.Text = "An exception occurred inserting the new Contact. " & _
        "Please verify the values in the newly inserted item."
    End If

    e.ExceptionHandled = True
  End If
End Sub

Keterangan

Secara default, ListView kontrol mengatur ulang nilai kontrol dari InsertItemTemplate templat ke nilai defaultnya setelah operasi penyisipan. Ini memungkinkan pengguna untuk menambahkan nilai untuk item baru yang akan disisipkan. Jika pengecualian dinaikkan selama operasi penyisipan, Anda dapat mempertahankan ListView kontrol dalam mode sisipkan dengan mengatur KeepInInsertMode properti ke true. Ini mempertahankan nilai dari upaya sebelumnya untuk menyisipkan item untuk kontrol di InsertItemTemplate dalam templat.

Berlaku untuk

Lihat juga