ListViewInsertedEventArgs.Exception Egenskap

Definition

Hämtar undantaget (om det finns något) som uppstod under infogningsåtgärden.

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

Egenskapsvärde

Undantaget som uppstod under infogningsåtgärden eller null om inget undantag uppstod.

Exempel

I följande exempel visas hur du använder objektet ListViewInsertedEventArgs som skickas till en hanterare för händelsen för ItemInserted att avgöra om ett undantag uppstod under infogningsåtgärden. Det här kodexemplet är en del av ett större exempel för ListViewInsertedEventArgs klassen.

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

Kommentarer

Om ett undantag har genererats och du hanterar undantaget i händelsehanteraren anger du ExceptionHandled egenskapen till true. Annars ListView genererar kontrollen undantaget igen.

Gäller för

Se även