KryptonListView Virtual Mode
Overview
KryptonListView is a themed wrapper around WinForms ListView. Virtual mode was previously commented out, so large-list consumers could not drive the control the same way as native ListView. Issue #3847 exposes the native virtual-mode surface on the wrapper.
Package: Krypton.Toolkit.
Architecture
KryptonListView hosts an inner InternalListView (System.Windows.Forms.ListView). Virtual-mode properties and events pass through to that inner control:
VirtualMode/VirtualListSizeread and write_listView.RetrieveVirtualItem,CacheVirtualItems,SearchForVirtualItem, andVirtualItemsSelectionRangeChangedare subscribed on_listViewand raised again withKryptonListViewas sender.- After
RetrieveVirtualItemreturns a non-nulle.Item,SetItemStateapplies palette colours and font (same path as non-virtual selection changes). UpdateStateAndPalettesdoes not enumerateItemswhenVirtualModeis true. Enumeration would fireRetrieveVirtualItemfor every row. Visible items are invalidated so the next retrieve reapplies palette colours.
Consumer --VirtualMode/VirtualListSize--> KryptonListView --> InternalListView
Consumer <--RetrieveVirtualItem/Cache...-- KryptonListView <-- InternalListView
Public API
Properties
| Member | Default | Notes |
|---|---|---|
bool VirtualMode |
false |
Same constraints as native ListView. |
int VirtualListSize |
0 |
Must be >= 0. Set after RetrieveVirtualItem is handled. |
Events
| Event | Required | Purpose |
|---|---|---|
RetrieveVirtualItem |
Yes when VirtualListSize > 0 |
Supply e.Item for e.ItemIndex. |
CacheVirtualItems |
No | Prefetch backing data for StartIndex–EndIndex. |
SearchForVirtualItem |
For FindItemWithText / type-ahead |
Set e.Index or -1. |
VirtualItemsSelectionRangeChanged |
No | Multi-select range changes in virtual mode. |
Usage
kryptonListView.View = View.Details;
kryptonListView.FullRowSelect = true;
kryptonListView.RetrieveVirtualItem += (sender, e) =>
{
e.Item = CreateItem(e.ItemIndex); // never leave Item null
};
kryptonListView.VirtualMode = true;
kryptonListView.VirtualListSize = data.Count;
Enable order: handle RetrieveVirtualItem, set VirtualMode = true while Items is empty, then set VirtualListSize.
After the backing store changes, update VirtualListSize and call Refresh or RedrawItems.
Native constraints (unchanged)
These are WinForms ListView rules, not Krypton-specific:
VirtualModecannot be turned on whileItems,CheckedItems, orSelectedItemscontain items.CheckBoxesandLabelEditare not supported.- Sorting and groups have limited or no support.
- Leaving
RetrieveVirtualItemunhandled (ore.Itemnull) throws when the control paints a virtual row.
Edge cases
- Theme changes: palette colours are applied in
OnRetrieveVirtualItemafter the consumer setse.Item. Do not walkItemsin virtual mode. - Details headers: the inner
SysHeader32is subclassed and painted withPaletteBackStyle.GridHeaderColumnList(same family as DataGridView list headers). Items remain native. - Krypton scrollbars: overlay bars keep
WS_VSCROLLon the innerListView(hiding only the native thumb) and sendLVM_SCROLLin pixels. RemovingWS_VSCROLLprevents virtual-mode scrolling. - Sender: events use the
KryptonListViewinstance, not the innerListView. - Designer:
VirtualModecan be true at design time whileVirtualListSizestays 0. WireRetrieveVirtualItemat runtime before raising the size. - C# / TFM: pass-through API;
net472and C# 7.3 compatible.