共用方式為


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

屬性值

要更新之項目的修訂值。

範例

下列範例示範如何使用 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 屬性。

適用於

另請參閱