I have been wondering for a while about the code below:
ListView1.View = View.Details
ListView1.Columns.Add("c1")
ListView1.Columns.Add("c2")
Dim Item As New ListViewItem
Item.Text = "1"
Item.SubItems.Add("2")
ListView1.Items.Add(Item)
'MsgBox(ListView1.Items(0).SubItems("c1").Text) 'this is wrong
MsgBox(ListView1.Items(0).SubItems(0).Text) 'this is right
I want a way to refer to the column by its name, because it is more readable, and lessens the chance of making a mistake. However, the program won’t build. Any thoughts?
You can specify name for
ListViewSubItemand refer to subitem by that name:If you add your subitems in this way,
MsgBox(ListView1.Items(0).SubItems("c1").Text)will work.Update:
Unfortunately, this won’t work for the first subitem. To fix this, you might need to create all subitems (including default) before
ListViewItem: