Unfortunately, ListView is a weird beast, and one of its weird angles is that its elements are just the set of values that will be shown, one for each column.
The Name property simply automates placing something in the first column, and, unfortunately, this “something” lives in the SubItems collection.
This means that if you check the SubItems collection, you will notice that it already has one element, and after setting the element name you will see that the text of this element is equal to this name.
This is the code for the ListViewItem.Name property:
public string Name { get { if (SubItemCount == 0) { return string.Empty; } else { return subItems[0].Name; } } set { SubItems[0].Name = value; } }
And the ListViewSubItem.Name property looks like this:
public string Name { get { return (name == null) ? "": name; } set { name = value; if (owner != null) { owner.UpdateSubItems(-1); } } }
Thus, clearing the SubItems collection has the consequences of clearing the properties of this first item, as you discovered, in addition to removing any other item from the collection.
In fact, it happens that the collection is cleared, but any attempt to search the SubItems collection while it is empty will create a new collection with one item with default values. In the above example, code reading the SubItems collection will automatically assign a collection with one item to the internal field if the collection is not already there.
So yes, that’s how it works. "
In fact, to remove every subitem except the first, your loop should be:
while (item.SubItems.Count > 1) item.SubItems.RemoveAt(1);