Share via


ListViewInsertedEventArgs.Exception 属性

定义

获取插入操作过程中引发的异常(如果引发)。

public:
 property Exception ^ Exception { Exception ^ get(); };
public Exception Exception { get; }
member this.Exception : Exception
Public ReadOnly Property Exception As Exception

属性值

在插入操作过程中引发的异常,如果未引发异常,则为 null

示例

以下示例演示如何使用 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。 否则,控件 ListView 会重新引发异常。

适用于

另请参阅