ListViewInsertedEventArgs.KeepInInsertMode 屬性

定義

取得或設定值,指出使用者的輸入值是否保留給 InsertItemTemplate 範本內的控制項。

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

屬性值

如果使用者的輸入值保留給 InsertItemTemplate 範本內的控制項則為 true,而如果使用者的輸入值會替換為控制項的預設值則為 false。 預設為 false

範例

下列範例示範如何在插入作業期間發生錯誤時,使用 KeepInInsertMode 屬性來保留使用者輸入的值。 此程式碼範例是提供給 類別之較大範例的 ListViewInsertedEventArgs 一部分。

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

備註

根據預設, ListView 控制項會在插入作業之後,將控制項的值從 InsertItemTemplate 範本重設為預設值。 這可讓使用者新增要插入之新專案的值。 如果在插入作業期間引發例外狀況,您可以將 屬性設定 KeepInInsertModetrue ,讓控制項保持 ListView 插入模式。 這會維護先前嘗試在範本內 InsertItemTemplate 插入控制項專案的值。

適用於

另請參閱