Rediger

Del via


ListViewUpdateEventArgs.NewValues Property

Definition

Gets a dictionary that contains the revised values of the item to update.

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

Property Value

The revised values of the item to update.

Examples

The following example shows how to use the NewValues property to make sure that the user has supplied all values before the data source is updated. This code example is part of a larger example provided for the ListViewUpdateEventArgs class.

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

Remarks

Use the NewValues property (dictionary) to access the values of the revised non-key fields in the item to update.

Note

The primary key field or fields are included in this dictionary if the primary key value or values are being updated. To access the original values of the primary key field or fields, use the Keys property. To access the original values of the non-key fields in the item, use the OldValues property.

The NewValues property is automatically populated with the name/value pairs of the revised fields in the item. A separate entry is added to the NewValues property for every field in the item.

To determine the field name of an entry, use the DictionaryEntry.Key property of a DictionaryEntry object that is contained in the NewValues dictionary. To determine the value of an entry, use the DictionaryEntry.Value property.

Applies to

See also