Search code examples
delphiheaderlistboxvirtualdelphi-xe

is there a virtual Listbox with headers in Delphi XE?


Sorry, background's a little convoluted on this one... I am in the process of converting a D5 project to DXE... It has a listbox with several thousand items. A full progressive text search is done on these items with each keystroke in the searchbox. In D5 (pre-virtual lists), I had to make my own virtual listbox using the LMD listbox (as there were several columns with headers in the listbox), a separate scrollbar and an Array of records. The Listbox would then be populated as the user navigated through the search results or by modifying the search. This performed very well but since now virtual listboxes are native to Delphi I was going to convert my custom listbox to the native one but I cannot find a listbox component with headers that is virtual-capable. Help?

Is there a component available that has virtual lists and headers/columns?

I forgot to mention: I am aware of Soft Gems VirtualTreeView components - these are excellent and is probably what I'll be using but... Is there a way in DXE to accomplish this without 3rd party utilities? I'm concerned that I'm missing something obvious in DXE as I've only been using it for about a month.


Solution

  • TListView is a thin wrapper around the Windows list view common control. Run it in virtual mode with report view style to achieve what I believe you are asking for.


    In order to set up a virtual list view you need to set OwnerData to True and supply an OnData event handler.

    procedure TVirtualListViewForm.FormCreate(Sender: TObject);
    begin
      ListView1.ViewStyle := vsReport;
      ListView1.Columns.Add.Caption := 'Column1';
      ListView1.Columns.Add.Caption := 'Column2';
      ListView1.OwnerData := True;
      ListView1.OnData := ListViewData;
      ListView1.Items.Count := 42;
    end;
    
    procedure TVirtualListViewForm.ListViewData(Sender: TObject; Item: TListItem);
    begin
      Item.Caption := Format('Column 0, index %d', [Item.Index]);
      Item.SubItems.Add(Format('Column 1, index %d', [Item.Index]));
    end;
    

    For your needs an OnDataFind may be needed to implement the progressive text search.