i'm using VirtualMode
to fill the columns like
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];
}
but i can not access the selected item. while accessing the selected item its throwing an error like Cannot access the selected items collection when the ListView is in virtual mode.
How do i get the selected items from the listView
when it is in VirtualMode
Please help me to do this.
From 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.
The Items collection is not available as an iterable collection in Virtual Mode but it is always possible to access a single element using Items(SelectedIndices(0)). I found that it works also using FULLROWSELECT. The problem is referenced on another page of this same site: Cannot access the selected items collection when the ListView is in virtual mode?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With