TListView OwnerData first row not reload properly
Original Reporter info from Mantis: chronos
-
Reporter name:
Original Reporter info from Mantis: chronos
- Reporter name:
Description:
If TListView is used in virtual mode (OwnerData = True) OnData event is not fired for first row if Refresh method called or Count property changed of TListView component. It occurs accidental or always if first row is selected (clicked by user).
This bug is related to Win32. Working good on Linux GTK2.
How to reproduce:
- Download attached example
- After run, click on button to populate list
- Click on first row in list
- Click button again and first row will not update
Additional information:
Class where problem ends is TOwnerDataListItem method SetDataIndex located in ComCtrls.pas(ListItem.inc) where
if FDataIndex <> ADataIndex then
begin
FDataIndex := ADataIndex;
...
end;
condition is checked. This reduce count of calling OnData event for same item index but prevent to reload same item where original value is different.
To force complete reload of all items in list we need to invalidate current OnData cache by loading for example index -1. So workaround out of LCL could be:
...
ListView.Items[-1]; // This change OnData cache last index to -1 so index 0 will be reloaded properly on refresh
ListView.Refresh;
...
But it would be better to solve this somehow inside LCL.