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

プロパティ値

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 テンプレートから既定値にリセットします。 これにより、ユーザーは新しい項目を挿入するための値を追加できます。 挿入操作中に例外が発生した場合は、プロパティtrueListView KeepInInsertMode .. これにより、テンプレート内にコントロールの項目を挿入しようとした前回の値が InsertItemTemplate 保持されます。

適用対象

こちらもご覧ください