Bagikan melalui


ListViewUpdateEventArgs.NewValues Properti

Definisi

Mendapatkan kamus yang berisi nilai item yang direvisi untuk diperbarui.

public:
 property System::Collections::Specialized::IOrderedDictionary ^ NewValues { System::Collections::Specialized::IOrderedDictionary ^ get(); };
public System.Collections.Specialized.IOrderedDictionary NewValues { get; }
member this.NewValues : System.Collections.Specialized.IOrderedDictionary
Public ReadOnly Property NewValues As IOrderedDictionary

Nilai Properti

Nilai item yang direvisi untuk diperbarui.

Contoh

Contoh berikut menunjukkan cara menggunakan NewValues properti untuk memastikan bahwa pengguna telah menyediakan semua nilai sebelum sumber data diperbarui. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ListViewUpdateEventArgs kelas .

void ContactsListView_ItemUpdating(Object sender, ListViewUpdateEventArgs e)
{
  // Cancel the update operation if any of the fields is empty
  // or null.
  foreach (DictionaryEntry de in e.NewValues)
  {
    // Check if the value is null or empty.
    if (de.Value == null || de.Value.ToString().Trim().Length == 0)
    {
      Message.Text = "Cannot set a field to an empty value.";
      e.Cancel = true;
    }
  }
  
  // Convert the email address to lowercase.
  String emailValue = e.NewValues["EmailAddress"].ToString();
  e.NewValues["EmailAddress"] = emailValue.ToLower();

}
Sub ContactsListView_ItemUpdating(ByVal sender As Object, ByVal e As ListViewUpdateEventArgs)
  
  ' Cancel the update operation if any of the fields is empty
  ' or null.
  For Each de As DictionaryEntry In e.NewValues
    ' Check if the value is null or empty
    If de.Value Is Nothing OrElse de.Value.ToString().Trim().Length = 0 Then
      Message.Text = "Cannot set a field to an empty value."
      e.Cancel = True
    End If
  Next
  
  ' Convert the email address to lowercase.
  Dim emailValue As String = e.NewValues("EmailAddress").ToString()    
  e.NewValues("EmailAddress") = emailValue.ToLower()
  
End Sub

Keterangan

NewValues Gunakan properti (kamus) untuk mengakses nilai bidang non-kunci yang direvisi dalam item untuk diperbarui.

Catatan

Bidang atau bidang kunci utama disertakan dalam kamus ini jika nilai atau nilai kunci utama sedang diperbarui. Untuk mengakses nilai asli bidang atau bidang kunci primer, gunakan Keys properti . Untuk mengakses nilai asli bidang non-kunci dalam item, gunakan OldValues properti .

Properti NewValues secara otomatis diisi dengan pasangan nama/nilai dari bidang yang direvisi dalam item. Entri terpisah ditambahkan ke NewValues properti untuk setiap bidang dalam item.

Untuk menentukan nama bidang entri, gunakan DictionaryEntry.Key properti DictionaryEntry objek yang terkandung dalam NewValues kamus. Untuk menentukan nilai entri, gunakan DictionaryEntry.Value properti .

Berlaku untuk

Lihat juga