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 对象。

注意

此属性仅适用于数据项。 它不适用于插入项目或空项。

适用于

另请参阅