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 模板重置为其默认值。 这样,用户便可以为要插入的新项添加值。 如果在插入操作期间引发异常,可以通过将KeepInInsertMode属性设置为true插入模式使控件保持ListView插入模式。 这会保留上一次尝试在模板中 InsertItemTemplate 插入控件项的值。

适用于

另请参阅