ListViewCancelEventArgs.ItemIndex Свойство

Определение

Возвращает индекс элемента, в котором содержится вызвавшая событие кнопка отмены.

public:
 property int ItemIndex { int get(); };
public int ItemIndex { get; }
member this.ItemIndex : int
Public ReadOnly Property ItemIndex As Integer

Значение свойства

Int32

Отсчитываемый от нуля индекс элемента, в котором содержится вызвавшая событие кнопка отмены.

Примеры

В следующем примере показано, как использовать ItemIndex свойство для определения индекса элемента редактирования, содержащего кнопку "Отмена", которая была нажата пользователем. Этот пример кода является частью более крупного примера, предоставленного ListViewCancelEventArgs для класса.

protected void ContactsListView_ItemCanceling(object sender, ListViewCancelEventArgs e)
{
  //Check the operation that raised the event
  if (e.CancelMode == ListViewCancelMode.CancelingEdit)
  {
    // The update operation was canceled. Display the 
    // primary key of the item.
    Message.Text = "Update for the ContactID " + 
      ContactsListView.DataKeys[e.ItemIndex].Value.ToString()  + " canceled.";
  }
  else
  {
    Message.Text = "Insert operation canceled."; 
  }
}
Protected Sub ContactsListView_ItemCanceling(ByVal sender As Object, _
                                             ByVal e As ListViewCancelEventArgs)
  'Check the operation that raised the event
  If (e.CancelMode = ListViewCancelMode.CancelingEdit) Then
    ' The update operation was canceled. Display the 
    ' primary key of the item.
    Message.Text = "Update for the ContactID " & _
      ContactsListView.DataKeys(e.ItemIndex).Value.ToString() & " canceled."
  Else
    Message.Text = "Insert operation canceled."
  End If

End Sub

Комментарии

ItemIndex Используйте свойство, чтобы определить индекс элемента, содержащего кнопку "Отмена", нажатой пользователем. Индекс элемента часто используется для извлечения элемента из Items коллекции ListView элемента управления, что позволяет получить доступ к свойствам элемента.

CancelMode Если свойству присвоено значениеListViewCancelMode.CancelingInsert, значение ItemIndex свойства всегда равно -1.

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

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