G
Guest
I have a form which has a ListView control named ListView1 added at design
time. When I add items using the following code, they don't appear in the
list view. However, if I create a ListView control in code and add it to the
form, it works. Why don't the items show up in the ListView that I added at
desgn time.
' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")
' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)
'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})
time. When I add items using the following code, they don't appear in the
list view. However, if I create a ListView control in code and add it to the
form, it works. Why don't the items show up in the ListView that I added at
desgn time.
' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")
' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)
'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})