public new int VirtualListSize
{
get { return base.VirtualListSize; }
set
{
// If the new size is smaller than the Index of TopItem, we need to make
// sure the new TopItem is set to something smaller.
if (VirtualMode &&
View == View.Details &&
TopItem != null &&
value > 0 &&
TopItem.Index > value - 1)
{
TopItem = Items[value - 1];
}
base.VirtualListSize = value;
}
}
I am trying to set the topitem property of listview, however in virtual mode items are disabled. so any code trying to access it in virtual mode throws an invalidoperation exception. Exception doesn't occur when i try to debug line by line. If i comment the line TopItem=Items[value-1] it doesnt throws any exception.
System.InvalidOperationException: When in VirtualMode the ListView RetrieveVirtualListItem event needs a list view SubItem for each ListView column. at System.Windows.Forms.ListView.WmReflectNotify(Message& m) at System.Windows.Forms.ListView.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) Please suggests.
You don't need to change the
TopItemwhen the virtual list size becomes smaller. The .NETListViewalready does that. According to dotPeek disassembler:This trouble with this is that, in my experience, setting
TopItemon a virtual listview is an error prone activity. In my code I have this block:Since setting
TopItemsometimes throws exceptions, this means that sometimes settingVirtualListSizesimilarly throws exceptions.Other points
You can access the
Itemscollection via an index even when in virtual mode. So, this is fine (assuming the list isn't empty):You can't iterate the
Itemscollection in virtual mode. This will throw an exception: