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。

适用于

另请参阅