我正在使用 VirtualMode
来填充像
List<ListViewItem> m_lstItem;
private void Form1_Load(object sender, EventArgs e)
{
m_lstItem = Enumerable.Range(0, 100000).Select(X => new ListViewItem(new String[] { X.ToString(), (X + 1).ToString() })).ToList();
listView1.VirtualListSize = m_lstItem.Count;
}
private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
e.Item = m_lstItem[e.ItemIndex];
}
但我无法访问所选项目。在访问所选项目时抛出错误,如 当 ListView 处于虚拟模式时无法访问所选项目集合。
listView
处于 VirtualMode
时如何获取选中的项目
请帮我做这件事。
最佳答案
来自 MSDN:
In virtual mode, the Items collection is disabled. Attempting to access it results in an InvalidOperationException. The same is true of the CheckedItems collection and the SelectedItems collection. If you want to retrieve the selected or checked items, use the SelectedIndices and CheckedIndices collections instead.
关于c# - 如何在 ListView 中使用虚拟模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5415877/