[英]ListView AddRange of Items starting from SubItem[1]
I have a ListView that already has a populated first column. 我有一个ListView已经有一个填充的第一列。
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? 我总是可以使用string[]
重载,但是有一种方法可以将ListViewItem[]
代替用于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 });
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
. 该方法需要一个strings
数组或ListViewSubItems
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.