HOW TO:使用 Windows Form ListView 控制項加入和移除項目
更新:2007 年 11 月
將項目加入至 Windows Form ListView 控制項的程序,主要包括指定項目和指派項目屬性。加入或移除清單項目 (List Item) 可於任何時候執行。
若要以程式設計方式加入項目
-
' Adds a new item with ImageIndex 3 ListView1.Items.Add("List item text", 3)
// Adds a new item with ImageIndex 3 listView1.Items.Add("List item text", 3);
// Adds a new item with ImageIndex 3 listView1.get_Items().Add("List item text", 3);
若要以程式設計的方式移除項目
使用 Items 屬性的 RemoveAt 或 Clear 方法。RemoveAt 方法會移除單一項目;Clear 方法則會移除清單中的所有項目。
' Removes the first item in the list. ListView1.Items.RemoveAt(0) ' Clears all items: ListView1.Items.Clear()
// Removes the first item in the list. listView1.Items.RemoveAt(0); // Clears all the items. listView1.Items.Clear();
// Removes the first item in the list listView1.get_Items().RemoveAt(0);