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。

適用於

另請參閱