ListViewUpdateEventArgs.NewValues 属性

定义

获取一个字典,其中包含要更新的项的修改后的值。

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

属性值

IOrderedDictionary

要更新的项的修改后的值。

示例

以下示例演示如何使用 NewValues 该属性来确保用户在更新数据源之前已提供所有值。 此代码示例是为类提供的大型示例的 ListViewUpdateEventArgs 一部分。

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

注解

NewValues使用属性 (字典) 访问要更新的项中修订的非键字段的值。

备注

如果更新主键值或值,则主键字段或字段将包含在此字典中。 若要访问主键字段或字段的原始值,请使用 Keys 该属性。 若要访问项中非键字段的原始值,请使用该 OldValues 属性。

NewValues 属性会自动填充项目中修订的字段的名称/值对。 将单独的条目添加到 NewValues 项中的每个字段的属性中。

若要确定条目的字段名称,请使用DictionaryEntry.Key字典中包含的NewValues对象的属性DictionaryEntry。 若要确定条目的值,请使用 DictionaryEntry.Value 该属性。

适用于

另请参阅