ListViewDataItem.DisplayIndex Właściwość

Definicja

Pobiera pozycję elementu danych, jak pokazano w kontrolce ListView .

public:
 virtual property int DisplayIndex { int get(); };
public virtual int DisplayIndex { get; }
public override int DisplayIndex { get; }
member this.DisplayIndex : int
Public Overridable ReadOnly Property DisplayIndex As Integer
Public Overrides ReadOnly Property DisplayIndex As Integer

Wartość właściwości

Int32

Pozycja elementu danych oparta na zera, jak pokazano w kontrolce ListView .

Implementuje

Przykłady

W poniższym przykładzie pokazano, jak za pomocą DisplayIndex właściwości pobrać indeks edytowanego elementu. Ten przykład kodu jest częścią większego przykładu podanego ListView.UpdateItem dla metody .

protected void PreferredCheckBox_CheckedChanged(object sender, EventArgs e)
{
  // Gets the CheckBox object that fired the event.
  CheckBox chkBox = (CheckBox) sender;

  // Gets the item that contains the CheckBox object. 
  ListViewDataItem item = (ListViewDataItem) chkBox.Parent.Parent;
  
  // Update the database with the changes.
  VendorsListView.UpdateItem(item.DisplayIndex, false);
}
Protected Sub PreferredCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) 

  ' Gets the CheckBox object that fired the event.
  Dim chkBox As CheckBox = CType(sender, CheckBox)
  
  ' Gets the item that contains the CheckBox object. 
  Dim item As ListViewDataItem = CType(chkBox.Parent.Parent, ListViewDataItem)
  
  ' Update the database with the changes.
  VendorsListView.UpdateItem(item.DisplayIndex, False)    

End Sub

Uwagi

Właściwość DisplayIndex odpowiada bieżącej pozycji elementu wyświetlanej przez kontrolkę ListView . Wartość każdego elementu DisplayIndex odzwierciedla kolejność, w jakiej zostały dodane do kontrolki w tej konkretnej stronie danych. Za pomocą DisplayIndex właściwości można pobrać ListViewDataItem obiekt w kolekcji Items .

Uwaga

Ta właściwość ma zastosowanie tylko do elementów danych. Nie ma zastosowania do wstawiania elementów ani pustych elementów.

Dotyczy

Zobacz też