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 В противном случае элемент управления повторно создает исключение.

Применяется к

См. также раздел