Link to home
Start Free TrialLog in
Avatar of Alpha_AI
Alpha_AI

asked on

How do I do a filter in a ListView

Hello I want the computer to find selected words in a ListView and highlight each of those words then reduce the ListView for display purposes to only contain the filtered results.

Anyone know how or got some code for it.
Ben
ASKER CERTIFIED SOLUTION
Avatar of AmigoJack
AmigoJack

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of laes_
laes_

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, strutils, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    Edit1: TEdit;
    procedure Edit1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  StrList : TStringList;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
   Index : Integer;
begin
     StrList := TStringList.Create;
     for Index := 0 to ListView1.Items.Count -1 do
        StrList.Add(ListView1.Items[Index].Caption);
end;
procedure TForm1.Edit1Change(Sender: TObject);
var
   Index : Integer;
begin
   ListView1.Clear;
   for Index := 0 to StrList.Count - 1 do
     if Pos(Edit1.Text, StrList.Strings[Index]) > 0 then
        ListView1.AddItem(StrList.Strings[Index], nil);
   if Edit1.Text = '' then
     for Index := 0 to StrList.Count - 1 do
       ListView1.AddItem(StrList.Strings[Index], nil);
end;


end.