DrawListViewItemEventArgs.ItemIndex 屬性

定義

在包含 ListViewItemItems 集合內取得 ListView 的索引。

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

屬性值

ListViewItem 集合內 Items 的索引。

範例

下列程式碼範例示範如何使用這個成員。 在此範例中,事件處理常式會報告事件的發生次數 ListView.DrawItem 。 此報告可協助您瞭解事件發生的時間,並可協助您進行偵錯。

若要執行範例程式碼,請將它貼入包含名為 ListView1 之類型 ListView 實例的專案。 然後,確定事件處理常式與 事件相關聯 ListView.DrawItem

private void ListView1_DrawItem(Object sender, DrawListViewItemEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "DrawDefault", e.DrawDefault );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Graphics", e.Graphics );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Item", e.Item );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Bounds", e.Bounds );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ItemIndex", e.ItemIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "State", e.State );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "DrawItem Event" );
}
Private Sub ListView1_DrawItem(sender as Object, e as DrawListViewItemEventArgs) _ 
     Handles ListView1.DrawItem

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "DrawDefault", e.DrawDefault)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Graphics", e.Graphics)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Item", e.Item)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Bounds", e.Bounds)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "ItemIndex", e.ItemIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "State", e.State)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"DrawItem Event")

End Sub

適用於

另請參閱