如何:使用 Windows Form ListView 控制項加入和移除項目
將專案新增至 Windows Forms ListView 控制項的程式主要是指定專案,並將屬性指派給它。 您可以隨時新增或移除清單專案。
以程式設計方式新增專案
-
// 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)
以程式設計方式移除專案
RemoveAt使用 屬性的 Items 或 Clear 方法。 方法 RemoveAt 會移除單一專案; 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.Items.RemoveAt(0) ' Clears all items: ListView1.Items.Clear()
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應