ListViewCancelEventArgs.ItemIndex プロパティ

定義

イベントを発生させた Cancel ボタンが格納されている項目のインデックスを取得します。

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

プロパティ値

イベントを発生させた Cancel ボタンが格納されている項目の 0 から始まるインデックス。

次の例では、 プロパティを 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 使用して、ユーザーがクリックした [キャンセル] ボタンを含むアイテムのインデックスを決定します。 項目インデックスは、多くの場合、コントロールのListViewコレクションから項目をItems取得するために使用されます。これにより、アイテムのプロパティにアクセスできます。

プロパティが CancelModeListViewCancelMode.CancelingInsert設定されている場合、プロパティの ItemIndex 値は常に -1 になります。

適用対象

こちらもご覧ください