Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.97 KB | None | 0 0
  1. procedure FilterItems(const Text: string; ListBox: TListBox);
  2. var
  3.   I: Integer;
  4.   Hide: Boolean;
  5.   Item: TListBoxItem;
  6.   Head: TListBoxGroupHeader;
  7. begin
  8.   Head := nil;
  9.   Hide := True;
  10.   ListBox.BeginUpdate;
  11.   try
  12.     for I := 0 to ListBox.Content.ControlsCount - 1 do
  13.     begin
  14.       if Text.IsEmpty then
  15.         ListBox.ListItems[I].Visible := True
  16.       else
  17.       if ListBox.ListItems[I] is TListBoxGroupHeader then
  18.       begin
  19.         if Assigned(Head) then
  20.           Head.Visible := not Hide;
  21.         Hide := True;
  22.         Head := TListBoxGroupHeader(ListBox.ListItems[I]);
  23.       end
  24.       else
  25.       if ListBox.ListItems[I] is TListBoxItem then
  26.       begin
  27.         Item := TListBoxItem(ListBox.ListItems[I]);
  28.         if Item.Text.ToLower.Contains(Text) then
  29.         begin
  30.           Hide := False;
  31.           Item.Visible := True;
  32.         end
  33.         else
  34.           Item.Visible := False;
  35.       end;
  36.     end;
  37.   finally
  38.     ListBox.EndUpdate;
  39.   end;
  40. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement