Listview and selected items lazarus / 31-LCL ---------------------------------------------------------------------- Arend041 · 2022-03-30 11:45 LS, I hope I can ask my question about selected items in a listview I use Lazarus 2.0.12 The listview in question is in report mode also multiselect and rowselect are checked further listview is running in virtualmode. I want to do an operation on some selected items. The selection is done by clicking on the first element and then with the contol key pressed click on another element to create a range of selected items. Now the code (slightly abbreviated):           while (ListView.Selected <> nil) do           begin               Application.ProcessMessages;               iSel := Listview.Selected.Index;               List.AddObject('', TObject(PtrUInt(iSel));               Listview.Items[iSel].Selected := False; //important           end; Check shows that iSel is 0, so no selected items found! If I click on the selected items piece by piece, with the control key pressed, only the last one clicked is detected. The following code obviously works, but takes too long with long lists:           for i := 0 to listview.Items.Count - 1 do           begin             if ListView.Items.Selected then             begin               Application.ProcessMessages;               iSel := Listview.Selected.Index;               List.AddObject('', TObject(PtrUInt(i));             end;           end; Why in the first case the selected items are not found, is it because of the listview or is it something else? In Delphi 7 the first code (while etc etc) works fine! ---------------------------------------------------------------------- wp · 2022-03-30 12:14 Sorry, I don't understand. What is that List? Which type? What is it good for? Please post a compilable little project which shows the issue (only .pas, .lfm,, .lpr and .lpi files packed as a common zip; upload via "Attachments and opther options") In the meantime, I created a demo on my own, but this is working correctly AFAICS. ---------------------------------------------------------------------- wp · 2022-03-30 12:55 While the former demo used the ListView in normal (=non-virtual) mode I am adding another demo which uses the Listview in virtual mode, and I can confirm the issue: After selecting several items and clicking the button, only the last selected item is marked as selected in the logging memo (I am writing an 'x' at the first position of the stringlist items, if the item is selected). [EDIT] Grrrr... This demo works only on Laz 2.2.0 or older. On Laz-main it is hanging when the button is clicked. There are several commits regarding virtualmode early this year... ---------------------------------------------------------------------- Arend041 · 2022-03-30 13:11 LS, thanks for the effort taken, it confirmed my suspicion that the virtual mode is causing the problems. ---------------------------------------------------------------------- wp · 2022-03-30 15:21 Thanks for posting the bug report (https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39693). But please, don't make it "confidential" - there's nothing to hide here ---------------------------------------------------------------------- Arend041 · 2022-03-30 15:55 That was a mistake, but now the posting has been moved and the (un)check button is no longer active. Sorry for the inconvenience. ---------------------------------------------------------------------- d7_2_laz · 2022-03-31 11:16 I think i've a feeling what's going on here. Myself i enforced the change mentioned after 2.2 heavily. For to solve a problem that made me headaches since the early phases of the 2.2.  Here, i noticed that when asking for "Selected" "too early" that would kill the virtual paradigm completely and let the runtime explode. All items would be instantiated at once and, boom. I'd never wish to see this performance killer reappear!! - Prob is described here, some readers may remember: https://forum.lazarus.freepascal.org/index.php/topic,57073.0.html This is the change that solved the problem: see picture "change_after_2.2.jpg", code within TCustomListView.GetSelection, the new lines are marked with gray background. Now back to the scenario forum_listview_multiselect-v2.zip: It seems to endless loop here. As within the "while Selected <> nil" loop it happens: "FSelectedIdx" never will change it's value. Obviously FSelectedIdx is not adapted when setting the listitem.Selected property to "false"! I tried to do some tests how the performance loss could be avoided and that recently described problem could be fixed too. See image "change_after_2.2_corr.jpg". On the left side the culprit changed 2.2 customlistview.inc.  On the right side the testwise done modification of this change: Of course it could be easily done to bundle those too loops into one, but applying either Items.Count - 1 or - dependingly - FSelectedIdx as the upper limit of the loop. For me it might look promising. ---------------------------------------------------------------------- d7_2_laz · 2022-03-31 12:00 So, a solution could be as such: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TCustomListView.GetSelection: TListItem;var  i, upperlimit: Integer;............     { according to Delphi docs we always must return first selected item,      not the last selected one see issue #16773 }    if not (lffSelectedValid in FFlags) or MultiSelect then  begin      FSelected := nil;      if (not FOwnerData) or (FSelectedIdx >= 0) then      begin         if MultiSelect and FOwnerData and (FSelectedIdx >= 0) then              upperlimit := FSelectedIdx       else upperlimit := Items.Count - 1;          for i := 0 to upperlimit do          begin             if Items[i].Selected then           begin                FSelected := Items[i];                break;             end;          end;      end; ---------------------------------------------------------------------- wp · 2022-03-31 12:14 Could you upload this to the bugtracker? It solves the hang, however, does not solve the original issue reported by Arend041 when the items are not selected in top-down order (i.e.: Select item 3, then item 2, then item1 --> The routine will detect only item 1 as selected). I guess the problem is deeper: How does TListView know which items are selected in virtual mode? It does not know anything about the data - they are provided by user-code in the OnData event handler. Note that even without taking care of any selected state in OnData, the selected items are marked as such by the Listview. Clearly, the OS must store this information (in other words: TListView does not have a "true" virtual mode!). I'd expect the Listview to move the FSelectedIdx to the next selected item; and for this it must query the widgetset which is missing. ---------------------------------------------------------------------- d7_2_laz · 2022-03-31 12:52 Yes  .. FSelectedIdx  hadn't been adapted, although the listitem had been deselected. I don't know the tools but try to upload a "patch-like" file  created using WinMerge later to the bugtracker. About the original problem, it's surely due to another problem solver i had been documentated for me as: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   procedure TCustomListView.CNNotify(var AMessage: TLMNotify);...              if (nm^.iItem < 0) or (nm^.iItem = FSelectedIdx) then                 //InvalidateSelected;                  begin                    // Workaround for problem Selected is nil, although items are selected by ArrowDown/ArrowUp                    // Problem is with ArrowDown/ArrowUp in combination with Shift.                    // See reply #21 in  https://forum.lazarus.freepascal.org/index.php/topic,553 98.msg413155.html#msg413155                     if not MultiSelect then                          InvalidateSelected;  It's due to the "if not MultiSelect then". Maybe somebody does know to solve the underlying issue better. ---------------------------------------------------------------------- wp · 2022-03-31 13:29 Sorry - this except is too short, I cannot locate the context in Laz- main- ---------------------------------------------------------------------- d7_2_laz · 2022-03-31 15:53 My fault wp, sorry .. It was not within the original 2.2, but later via https://gitlab.com/freepascal.org/lazarus/lazarus/- /blob/main/lcl/include/customlistview.inc and, here, source line 359. The reason why is described herein as part of some other probs: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39324 -> Here, navigate to the following text: "AND (otherwise Navigation by arrow keys (VK_UP, VK_DOWN) would set  listview "Selected" object to nil. You can check that with the test project attached, listview_virtualMode_multiselect_selected_behaviour_ArrowKeys.zip):" ---------------------------------------------------------------------- wp · 2022-03-31 16:37 Quote from: d7_2_laz on March 31, 2022, 05:53:06 pmMy fault wp, sorry .. No, sorry from my side - I should have seen it but after bisecting for the commit which caused the hang I had forgotten to switch git back to main. ---------------------------------------------------------------------- wp · 2022-03-31 20:13 Quote from: d7_2_laz on March 31, 2022, 02:00:03 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TCustomListView.GetSelection: TListItem;...          for i := 0 to upperlimit do          begin             if Items[i].Selected then           begin                FSelected := Items[i];                break;             end;          end;      end; What I don't understand is: Why do we have to iterate over all items to find the selected item? When the widgetset stores the information which items are selected (it does because no user code is required to highlight the multi-selected items in virtual mode) then there should be methods to retrieve only the selected items from the widgetset. According to https://codeverge.com/embarcadero.cppbuilder.using/virtual-listview- fastest-way-to/1068377 there seems to be a Win32 message LVM_GETNEXTITEM which can be set up to jump from selected item to selected item (https://docs.microsoft.com/en- us/windows/win32/controls/lvm-getnextitem). Therefore, it should be possible to avoid this loop altogether, at least for Windows. ---------------------------------------------------------------------- d7_2_laz · 2022-03-31 20:52 Yes yes yes! Absolutely agree. It's only a "compromise". The "improvement" mentioned is very very relative. In fact it has a high price. This is because it does re-involve looping again. In in diminished form, but it does. The result is: after having created a heavily populated list, then going to the end (eg. by Ctrl-End), and retrieving "Selected" here, that would take forever again. (Foreever not due to the loop itself, but mainly to all those items that will be unintendedly instantiated until one reaches the first "selected"). Whenever it is possible to avoid such loop procedures and to use better approaches - the more if they turn out to be already potentially available -  that would be really a tremendous hit. ---------------------------------------------------------------------- wp · 2022-03-31 20:54 Here's a (Windows-only) feasibility study for the idea in the previous post: Based on the previous test project I implemented methods GetFirstSelectedItem and GetNextSelectedItem in a sub-classed TListView. When, after selecting multiple items in the listview, the button is clicked these methods are called, and they, in fact, correctly retrieve the list of selected items without having to iterate through all items. Next step would be to extend the widget class TWSCustomListView by these methods for the win32 widgetset and to call them in the TCustomListView.GetSelection method instead of looping through all the items. After that comes the hard part: Revert all the meandering commits related to the multi-selection issues of the virtual listview. d7_2_laz: I did not follow all these commits too closely, and you seem to know this issue best: Can you tell me which was the first commit in which it was attempted to fix the "runtime explosion" issue? Before I continue, could you also test my feasibility project regarding runtime performance with many more items? (I am asking because Microsoft might be looping over all items here as well...). ---------------------------------------------------------------------- d7_2_laz · 2022-04-01 08:47 If i remember right the issue was caused in the early 2.2 RC1 by commiting a patch that should help (among others) too assure that Selected returns the first element instead of the last element, By that the looping was introduced and the trouble started. The solution of major parts of the performance issue was done via: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39324 as 4d722455 (for 2.2.2) https://gitlab.com/freepascal.org/lazarus/laza rus/-/commit/4d7224555268fbcddaf0a46e18497ec84ef5f5cb with related  082d0514  https://gitlab.com/freepascal.org/lazarus/laza rus/-/commit/082d051466dc04a269d3b3113f669cb97e7f30f2 I need to underline that i'm very very grateful for the patch because it helped a lot to stop major parts of the nightmare. I tried the v3 feasability project. Appears to work fine! Quick check against scattered selection (= that are not in a sequence; via Ctrl and Click) -> results as expected Did set MAX to 30000 -> no performance impact Tried  to enforce the "early instantiation" scenario (= are there unwanted item instantiations if i do the work done within Button1Click directly after the assignment to Items.Count ?) -> no issue i could see. Looks promising, wonderful! sigh ... Later the day i'll try how it will behave with Shift + Arrow keys. And check if de-selections are correctly done when clicking on an empty space of the listview. Just for info: it's near by the Delphi 7 approach. Just for interest i attach a short snippet from D7. I think D7 is slosely to Windows and uses it's OS capabilities. Lazarus is cross-platform for very good reasons! This is a target conflict that is sometimes hard to resolve of course. On the other hand, with D7 i never encountered such virtual / multiselection issues. ---------------------------------------------------------------------- wp · 2022-04-01 09:05 Quote from: d7_2_laz on April 01, 2022, 10:47:36 amJust for interest i attach a short snippet from D7. Please remove this - we don't want to give the slightest evidence of copyright infringement. ---------------------------------------------------------------------- wp · 2022-04-01 09:11 A complication: Trying to document the status-quo I noticed that the TListview test mentioned by Martin at https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39324 does not pass successfully. Did you ever run this test ((lazarus)/test/runtestsgui, node "LCL tests" > "TTestListView" > "TestClick")/? According to dsiders in this bug report, it should run fine - so the failures observed by me are new issues? ---------------------------------------------------------------------- d7_2_laz · 2022-04-01 09:20 Ok, removed the attachment. No, i didn't tun this script. - For info, need to be out for some hours now, will be back later the day. ---------------------------------------------------------------------- wp · 2022-04-01 10:41 Good news: Found in the sources that my GetFirstSelecteditem/GetNextSelectedItem are already implemented as TListView.GetNextItem. For win32 this calls the API function that I mentioned, for other widgetsets it loops through the items. The job is now to replace the loop in GetSelection by GetNextItem. my first attempts failed (endless loop again), however, because I did not get the conditions right when and how this should be called. Maybe you can help... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TCustomListView.GetSelection: TListItem;var  i: Integer;begin  if OwnerData and not MultiSelect then  begin    if FSelectedIdx>=0 then begin      FOwnerDataItem.SetDataIndex(FSelectedIdx);      Result:=FOwnerDataItem;    end else      Result:=nil;  end  else begin    { according to Delphi docs we always must return first selected item,      not the last selected one see issue #16773 }    if not (lffSelectedValid in FFlags) or MultiSelect then    begin      if MultiSelect and FOwnerData and (FSelectedIdx >= 0) then        FSelected := Items[FSelectedIdx]      else      begin        FSelected := GetNextItem(nil, sdAll, [lisSelected]);        if FSelected <> nil then          FSelectedIdx := FSelected.Index        else          FSelectedIdx := -1;      end;        Include(FFlags, lffSelectedValid);    end;    Result := FSelected;  end;end; [EDIT] The endless loop is gone when the "if not MultiSelect then" is removed in CNNotify that you mentioned. Virtual mode seems to work this way. However, when I go back to non-virtual mode the hang is back. ---------------------------------------------------------------------- d7_2_laz · 2022-04-01 14:19 Hi wp, regarding the hang, it's just as before (with forum_listview_multiselect-v2). It will disappear by removing the patch 082d0514  concerning the arrow keys; that does mean: within CNNotify, Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       if not MultiSelect then    //  this condition had been added by the patch 082d0514         InvalidateSelected; But don't deactivate this condition now. That is not needed.  Because: maybe you had been more successful than you realized: Just as before, we cannot really rely on FSelectedIdx here. After some attempts it looks promising simply to do (within GetSelection): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     if not (lffSelectedValid in FFlags) or MultiSelect then    begin      if MultiSelect and FOwnerData and (FSelectedIdx >= 0) then        //FSelected := Items[FSelectedIdx]        FSelected := GetNextItem(nil, sdAll, [lisSelected])     else At least for the est project v2 it appears to - surprisingly! - deliver the right result so far.. And, moreover, the if-else branch itself maybe no longer needed, but this would require far  more tests and use cases. What do you think? ---------------------------------------------------------------------- d7_2_laz · 2022-04-01 15:00 Sorry wp, i hadn't recognized your [EDIT] at that time  Could you retry with the modification i just mentioned? I just did rerun my test project for the patch 082d0514  cconcerning Shift and arrow keys. Results: with having applied the patch (Cnnotify, "if not MultiSelect then") : the results are no longer ok with reverting the change (deactivating "if not MultiSelect then"):  results are fine. My impression: Shift + arrow keys work, but only when reverting the patch = the previously needed workaround. For easyness i reattach the test project here. ---------------------------------------------------------------------- d7_2_laz · 2022-04-01 15:29 Did rerun my test project about "runtime explosion" (by unintending instantiation of all list objects). Scenario: navigate to a highly populated folder (ie windows\system32 or windows\WinSxS) and press the button who shows how oftenly OnData had been called. Result appears to be fine. Slighlty more calls, but no noticeable slowdown or functional anomalie. For easyness test project is reattached. ---------------------------------------------------------------------- wp · 2022-04-01 15:32 Good. My GetSelection method now is like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TCustomListView.GetSelection: TListItem;var  i: Integer;begin  if OwnerData and not MultiSelect then  begin    if FSelectedIdx>=0 then begin      FOwnerDataItem.SetDataIndex(FSelectedIdx);      Result:=FOwnerDataItem;    end else      Result:=nil;  end  else begin    { according to Delphi docs we always must return first selected item,      not the last selected one see issue #16773 }    if not (lffSelectedValid in FFlags) or MultiSelect then    begin      FSelected := GetNextItem(nil, sdAll, [lisSelected]);      if FSelected <> nil then        FSelectedIdx := FSelected.Index      else        FSelectedIdx := -1;      Include(FFlags, lffSelectedValid);    end;  Result := FSelected;  end;end; My virtual-mode and non-virtual-mode tests are running fine now; your keyboard test is running fine as well. No matter whether "if not MultiSelect then" is in CNNotify or not. Your keyboard test yields no output when CTRL is pressed, then Arrow key, then SPACE - did not check wether this is an oversight or not. While all this looks promising there is one serious drawback: The GetNextItem method gets the selected item from the widgetset only for win32. In Linux (gtk2/qt/qt5) and macOS (cocoa) the method is not implemented and thus does what is implemented for the base widget class, TWSCustomListView: iterate through all items: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //Default implementationclass function TWSCustomListView.GetNextItem(const ALV: TCustomListView;  const StartItem: TListItem; const Direction: TSearchDirection; const States: TListItemStates): TListItem;var  ACount: Integer;  StartIndex, AIndex: Integer;begin  Result := nil;  if StartItem = nil then    Exit;  StartIndex := StartItem.Index;  AIndex := StartIndex;  ACount := ALV.Items.Count;  case Direction of  sdAbove:      while AIndex>0 do      begin        dec(AIndex);      if States <= ALV.Items[AIndex].GetStates then          Exit(ALV.Items[AIndex]);      end;    sdBelow:      while AIndex < ACount-1 do      begin        inc(AIndex);        if States <= ALV.Items[AIndex].GetStates then          Exit(ALV.Items[AIndex]);    end;    sdAll:      while True do      begin        inc(AIndex);      Assert(AIndex <> StartIndex, 'TWSCustomListView.GetNextItem: AIndex=StartIndex');        if AIndex >= ACount then          Exit;{     begin           Do not wrap around. Will never return Nil. Issue #38565.          AIndex := -1;  continue;        end;  }        if States <= ALV.Items[AIndex].GetStates then          Exit(ALV.Items[AIndex]);      end;  end;end; Therefore, I think removing the line "FSelected := Items[FSelectedIdx]" cannot be accepted. Unfortunately I have no experience in gtk2/qt/cocoa programming and cannot tell whether a similar functionality exists like the Windows ListView_GetNextitem. Of course, we somehow could try to keep track of the selected items in TCustomListView... ---------------------------------------------------------------------- d7_2_laz · 2022-04-01 15:59 Hello wp, for now only a few remarks: - the removal of the if - else resp. your recent code change below would exactly meet my thoughts - the keyboard test: was not intended as overall keyboard test, it was only specified for the problem i did encounter (Shift and Arrow keys) - Windows specifcs vs. cross-platform: just thought about this the moring, that it would be problem. - Unfortunately, i'm on Windows only. Rough idea: why not to branch OS-specifically? Or - idea for to allow a smooth transition: - make it, maybe temporarely, dependent on an optional property that one could use or not?  Something like: Use_win_selectionmode. Benefit: could allow exhaustive testing without impact on existing apps or OSes. Could allow a stabilization phase. I could imagine very well it's very hard to find solutions that are, immediately, fine for all platforms and layers and widgetsets. ---------------------------------------------------------------------- wp · 2022-04-01 16:24 Quote from: d7_2_laz on April 01, 2022, 05:59:29 pmRough idea: why not to branch OS-specifically? No. I once added OS-specific defines to the ShellCtrls units, and it ended up in a mess (because it is possible to write applications in Windows that use the widgetsets typical of Linux). The correct way to handle these differences is in the widgetset architecture - that's what it was made for. Just played with Ubuntu and the modificed ListView of my prev post, and it is not usable when there are more than a few items, in both normal and virtual modes. I think the best approach is to equip TCustomListView with a TList for the selected items. Whenever (in a non-win32 widgetset) an item is selected or deselected it is added to or removed from the list. Then I can rewrite the TWSCustomListview.GetNextItem to just iterate through this short list of selected items rather than all list items. Of course, this breaks the virtual paradigm to some degree because the selected state is stored by the ListView, rather than by a user- defined data structure. Well - Windows does exactly this... Did you ever try to check the case when the user selects all items and there are a million of them? How does the Windows solution work here? ---------------------------------------------------------------------- d7_2_laz · 2022-04-01 17:11 QuoteDid you ever try to check the case when the user selects all items and there are a million of them? Honestly of course not. I was happy enogh that after months of exchange with the latest commits the honorable speed was back to present let's say 17000 file system objects in the listview quickly .. not thinking about millions. However I understand your argement well. But what should happen with the original issue of this thread? ---------------------------------------------------------------------- wp · 2022-04-01 17:22 Quote from: d7_2_laz on April 01, 2022, 07:11:14 pmBut what should happen with the original issue of this thread? It has to be solved along with yours - it all the same issue basically. ---------------------------------------------------------------------- d7_2_laz · 2022-04-01 18:03 wp, from my side, with big respect, many compliments for your improvements and ideas! As closing info only: for to see all pieces together about listview + ownerdata + multiselect, there's still one possible commit in the pipeline. #39325  Virtual listview, MultiSelect: problem: only one item in the list: after click on empty space this single item keeps to stay selected    https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39325 Workaround and test project herein. Maybe it will be committed later. I retried it. Result is: it is not affected by your code change, not positively and not negatively. The workaround will still be required and still will work (i'm using it since months). ---------------------------------------------------------------------- d7_2_laz · 2022-04-03 14:37 After two days of heavy usage of the change as part my own working environment i'd like to share my recent impressions (on win 10 x64). I applied the patch as above (TCustomListView.GetSelection as of reply #24). Having reverted 4d722455 as well as 082d0514. Upto now i encountered none(!) side effects. Nobody can exclude that there might exist some in different usage scenarios, of course. But i didn't notice any yet. Moreover a couple of flaws and compromises disappeared that i did know about but never communicated due minor importance, compared with the main issues. For instance, now i can have a context menu on the last element of a long list immediately, and not with delay (that was already known, but more or less priced in for to have at least a fast initial population). So, the patch keeps the benefit of 4d722455 and does even more. Some previously needed complementary workarounds on app level might be removed later. At least for Windows with this change the "Selected" behaviour imo is back to work great again. ---------------------------------------------------------------------- wp · 2022-04-03 22:21 I committed a version to Laz-main which uses the ListView_GetNextItem macro for Windows and a list with all selected items for the other widgetsets so that iteration over all list items is no longer necessary. The code now is included in the widgetset infrastructure of the LCL. For Windows the performance should be as discussed in this thread, and on Linux etc, it - well - should not be worse than before (the problem here is that gtk2 seems to iterate over all items even in virtual mode, and this causes a dramatic slowdown when "many items are selected). Since I cannot test anything else than win32 and gtk2 widgetsets at the moment, user tests would be welcome. Here is the test project that I used. ---------------------------------------------------------------------- dsiders · 2022-04-04 06:43 Quote from: wp on April 04, 2022, 12:21:45 amI committed a version to Laz-main which uses the ListView_GetNextItem macro for Windows and a list with all selected items for the other widgetsets so that iteration over all list items is no longer necessary. The code now is included in the widgetset infrastructure of the LCL. For Windows the performance should be as discussed in this thread, and on Linux etc, it - well - should not be worse than before (the problem here is that gtk2 seems to iterate over all items even in virtual mode, and this causes a dramatic slowdown when "many items are selected). Since I cannot test anything else than win32 and gtk2 widgetsets at the moment, user tests would be welcome. Here is the test project that I used. I used a TStringList instead of TMemo for the logging output when processing the multi-selected items. This reduced the time for all 1,000,000 items from 853 seconds to 43 seconds on my ancient laptop. ---------------------------------------------------------------------- d7_2_laz · 2022-04-04 09:11 As i saw that now a couple of base files are involved in the commit, i cloned the "main" repository to Windows (can test Windows only) and focused on a re-test of test projects as mentioned earlier here. For to give a fast feedback: my first impression (will go more close into them later) is: indeed, basically it appears to work as fine as the prototype patch (as of reply #24)  on Windows, regarding the functionality. Re-tested with my application: the same: bbasically fine! Just for interest i did a speed test comparison of both versions (protobype vs. the committed patch) / Windows: - large folder (windows\system32) approx. 94 ms -> both - very large folder (windows\WinSxS) approx. 500 ms -> both I'm so much  impressed about this change so far! Very interested to see what others are saying / other platforms. Besides: issue #39325 (see reply #29) will not be affected [EDIT: -->   this issue will be solved by the latest change this morning, commit 9aa8b52b ] ---------------------------------------------------------------------- Arend041 · 2022-04-07 18:16 When I run in Laz 2.20 program listview_virtualMode_multiselect_prob_Keyup_Shift_2 with Checkboxes checked I get a fatal error with a reference to TCustomListView DoItemChecked when selecting by mouse and ctrl key. ---------------------------------------------------------------------- wp · 2022-04-07 20:37 As far as I know, it is not possible to display checkboxes in a listview operating in virtual mode. If you have to, you should add checkbox images to the StateImages of the listview and select the image index of the checked and unchecked images when checking or unchecking an item. (https://stackoverflow.com/questions/7899185/using-checkbox-in- virtual-mode-listview, https://forum.lazarus.freepascal.org/index.php?topic=43603.0).