Share via


ListViewInsertedEventArgs.ExceptionHandled 属性

定义

获取或设置一个值,该值指示在插入操作过程中所引发的异常是否已在事件处理程序中得到处理。

public:
 property bool ExceptionHandled { bool get(); void set(bool value); };
public bool ExceptionHandled { get; set; }
member this.ExceptionHandled : bool with get, set
Public Property ExceptionHandled As Boolean

属性值

如果异常已在事件处理程序中得到处理,则为 true;否则为 false。 默认值为 false

示例

以下示例演示如何使用 ListViewInsertedEventArgs 传递给 事件的处理程序 ItemInserted 的对象来确定在插入操作期间是否引发了异常。 此代码示例是为 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

注解

在插入操作期间引发异常时,请使用 ExceptionHandled 属性指示是否在事件处理程序中处理了异常。 当此属性设置为 true时,异常被视为已处理且不会重新引发。 如果此属性设置为 false,则 ListView 控件将重新引发异常。 若要确定引发的异常,请使用 Exception 属性。

适用于

另请参阅