When using
lvi.SubItems.AddRange(new ListViewItem.ListViewSubItem[5]);
Debug.Assert(lvi.SubItems.Count == 5);
the assert fails, lvi.SubItems.Count is 1, and accessing lvi.SubItems[1]
fails.
What? Shouldn't that add 5 items?
(To clarify: I know I can add them individually using Add() - I'm asking why this doesn't work)
Larger context: listView1 is a winforms listview in Details view with 6 columns added:
public Form1()
{
InitializeComponent();
ListViewItem lvi = new ListViewItem();
listView1.Items.Add(lvi);
int expectedCount = 6;
Debug.Assert(listView1.Columns.Count == expectedCount);
if (lvi.SubItems.Count != expectedCount - 1)
{
lvi.SubItems.Clear();
lvi.SubItems.AddRange(new ListViewItem.ListViewSubItem[expectedCount - 1]);
Debug.Assert(lvi.SubItems.Count == expectedCount - 1);
}
}
(VS Express 2013RC, VS 2008 Pro)