将项添加到 Windows 窗体 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 属性的 Clear 和 Items 方法。 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()