ListViewCancelEventArgs.ItemIndex Property

Definition

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

C#
public int ItemIndex { get; }

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.

C#
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."; 
  }
}

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

Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also