Reputation: 1142
I have a ListView that already has a populated first column.
I can easily use :
MylistView.Items.AddRange(new ListViewItem[] { item })
but since I already have the first column populated, I tried using:
MylistView.Items[0].SubItems.AddRange(new ListViewItem[] { item })
but I just get an error:
I can always use the string[]
overload, but is there a way to use the ListViewItem[]
instead for the Subitems?
Here's my code:
ListViewItem item = new ListViewItem(new string[]
{
exp[listBox1.SelectedIndex].ToString(),
exp2[listBox1.SelectedIndex].ToString()
});
listView2.Items[0].SubItems.AddRange(new ListViewItem[] { item });
Upvotes: 1
Views: 3251
Reputation: 101681
So why don't you just do:
listView2.Items[0].SubItems
.AddRange(new [] { exp[listBox1.SelectedIndex].ToString(),
exp2[listBox1.SelectedIndex].ToString(),
});
The method expects either an array of strings
or ListViewSubItems
.
Upvotes: 1