ListViewDataItem.DisplayIndex 屬性

定義

取得 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

屬性值

ListView 控制項中所顯示資料項目之以零起始的位置。

實作

範例

下列範例示範如何使用 DisplayIndex 屬性來擷取正在編輯之專案的索引。 此程式碼範例是為 方法提供之較大範例的 ListView.UpdateItem 一部分。

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

備註

屬性 DisplayIndex 會對應至 控制項所顯示 ListView 之專案的目前位置。 每個專案 DisplayIndex 的值都會反映新增至該特定資料頁控制項的順序。 您可以使用 DisplayIndex 屬性來擷取 ListViewDataItem 集合中的 Items 物件。

注意

此屬性只適用于資料項目。 它不適用於插入專案或空白專案。

適用於

另請參閱