Bewerken

Delen via


ListViewCancelEventArgs.ItemIndex Property

Definition

Gets the index of the item that contains the Cancel button that raised the event.

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

Property Value

The zero-based index of the item that contains the Cancel button that raised the event.

Examples

The following example shows how to use the ItemIndex property to determine the index of the edit item that contains the Cancel button that was clicked by the user. This code example is part of a larger example provided for the ListViewCancelEventArgs class.

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

Remarks

Use the ItemIndex property to determine the index of the item that contains the Cancel button clicked by the user. The item index is often used to retrieve the item from the Items collection of the ListView control, which enables you to access the item's properties.

When the CancelMode property is set to ListViewCancelMode.CancelingInsert, the value of the ItemIndex property is always -1.

Applies to

See also