Adding an item to the ListView control is very similar to adding items to a ListBox control, however you have much more options. The following code, simply adds a few items, with no icons to ListView1:
ListView1.ListItems.Add , ,"Fred"
ListView1.ListItems.Add , ,"Sarah"
ListView1.ListItems.Add , ,"Paul"
You will notice that I have missed two parameters before specifying the text. The first specifies the Index (a unique number) to that item. If you leave that option blank, the ListView will automattically add a unique Index. The second parameter specifies a key. This is a unique string that can also be used to identify that item. If left blank, no key will be assigned.
To remove an item, simply use this syntax. Replace 1 with its index or the items key.
ListView1.ListItems.Remove(1) '// removes the first item
So, to remove the selected item, you would use:
ListView1.ListItems.Remove(ListView1.SelectedItem) '// removes the selected item
Comments