Filtering a TStringGrid. Suggestions? lazarus / 31-LCL ---------------------------------------------------------------------- EganSolo · 2025-06-11 21:57 I'm looking for a component that filters TStringGrid content. Before coding, I thought I'd ask if such a component exists. Thank you for your suggestions! ---------------------------------------------------------------------- n7800 · 2025-06-11 22:48 Just the first topic I found: https://forum.lazarus.freepascal.org/index.php?topic=68362 ---------------------------------------------------------------------- EganSolo · 2025-06-11 23:04 n7800: thanks for the links. I guess, I wasn't clear enough: I'm looking for a visual component that sits on top of the grid to let the user type the strings (one per column) that they want to filter on. The links you provided discuss how to hide the filtered out rows. ---------------------------------------------------------------------- n7800 · 2025-06-11 23:31 The first message also contains links where you can immediately find a mention of "VirtualTreeView" (which I have not checked, just a quote): https://forum.lazarus.freepascal.org/index.php/topic,25791.msg157130.h tml#msg157130 But it seems I understood that you mean a separate component like TListFilterEdit/TListViewFilterEdit? Personally, I do not know such a thing. Perhaps you will write it )) In one of my programs, I also had to implement a descendant of the TStringGrid class to implement a filter. By the way, I placed them as an additional line under the header (under the column names), in my opinion, more compact than a separate panel. ---------------------------------------------------------------------- EganSolo · 2025-06-12 01:56 My initial attempt was similar to your solution: I instantiated a separate StringGrid to use as a filter. The somewhat (well, slightly) tricky part is that I want interactive filtering, which hides or shows rows in the grid as the user modifies the filter. My data requirement is modest (less than a thousand rows), and thus it is possible. However, it implies that I need to keep track of the internal editor the grid uses and hook into that editor's OnKeyPress and OnKeydown events. It's feasible, but the code is more obscure. I'm going to think some more ... ---------------------------------------------------------------------- n7800 · 2025-06-12 02:30 I also used a different solution. I created a TEdit for each column at runtime and aligned them to cells via the OnDrawCell event. Just a small demo (I can't share the program itself): 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 TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect; aState: TGridDrawState);var  lGrid: TMyStringGrid absolute Sender;begin  if aRow = 1 then    case aCol of      cColNumbers: lGrid.edtNumbers.BoundsRect := aRect;      cColName   : lGrid.edtName   .BoundsRect := aRect;      cColUnits  : lGrid.edtUnits  .BoundsRect := aRect;    end;end;  So all filters are interactive. Of course, instead of constants, I could have used a TEdit array and looped through it, but that wasn't necessary in this program. The only thing left was to do all this in a separate component, not a form, but I did not finish it. ---------------------------------------------------------------------- paweld · 2025-06-12 11:58 maybe instead of TStringGrid use TDBGrid and dxDBGridController ( https://wiki.freepascal.org/TdxDBGridController#Global_search ) and keep the data in BufDataSet instead of in the grid ---------------------------------------------------------------------- Hansvb · 2025-06-12 16:33 Coincidentally, this week I have also been looking for how to filter a TStringGrid. My conclusion was, replace TStringGrid with a TDBGrid. In my case, I retrieved the data with a TSQlquery anyway. TSQlquery has a ServerFilter property. That works well. Quotehttps://www.freepascal.org/docs- html/fcl/sqldb/tsqlquery.serverfilter.html Quotehttps://www.youtube.com/watch?v=VlU925xHOAc ---------------------------------------------------------------------- Nicole · 2025-06-12 20:52 What about TDBStringGrid? Or even TDynamicGrid? The first one has a filter event and the second one a sort function, which works like the click at the columns in Excel.