How to search a FMX.TListView header as well as items


I have a LiveBindings databound FMX.TListView with the FieldName being Stage and the FillHeaderFieldName being Production. When the app is running, I see a list of Productions using the HeaderAppearance, and within each Production, there is a list of Stages using the ItemAppearance. I’ve turned on SearchVisible to get the components search panel to show at the top of the list.

Currently, typing into the search box only filters on the Stage, and not the Production.

I’d like to be able to do both, and I’d like to be able to do it without making another REST call with filter parameters. I understand I would probably need to write an event handler for the OnSearchChange event, and I have this bit of code to get the search text entered:

List := Sender as TListView;

for I := 0 to List.Controls.Count-1 do
if List.Controls[I].ClassType = TSearchBox then
SearchBox := TSearchBox(List.Controls[I]);

And I think I need to set the Items.Filter property, and I used this bit of code:

Lower := LowerCase(SearchBox.Text.Trim);

List.Items.Filter :=
function(X: string): Boolean
Result:= (Lower = EmptyStr) or LowerCase(X).Contains(Lower);

One of the problems is that the ListView component is applying its filtering as soon as a character is typed, while the OnSearchChange event only fires when the searchbox loses focus.

The second problem is that, even after the event is fired and the new filter function set, nothing happens to the list.

I’ve confirmed that the List.Items collection in my “36” example does actually contain all 6 items – the 3 header items and the 3 detail items – so I’m unsure why the filter is not applying to the header items as it does the detail items.

Comments are closed.