共用方式為


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 控件會重新擲回例外狀況。

適用於

另請參閱