Author: Tomas Rutkauskas How to search up and down in a TListView Answer: 1 procedure TRememberMenu.FindDialog1Find(Sender: TObject); 2 var 3 MaxLines, Adder, CurrentLine, X: Integer; 4 LookText: string; 5 Found: Boolean; 6 begin 7 {Find the word} 8 Found := False; 9 MaxLines := ListView1.Items.Count - 1; 10 LookText := UpperCase(FindDialog1.FindText); 11 if ListView1.Selected <> nil then 12 CurrentLine := TListItem(ListView1.Selected).Index 13 else 14 CurrentLine := 0; 15 X := CurrentLine; 16 if frDown in FindDialog1.Options then 17 begin 18 Adder := 1; 19 end 20 else 21 begin 22 Adder := -1; 23 end; 24 X := X + Adder; 25 if (X >= 0) and (X <= MaxLines) then 26 begin 27 repeat 28 begin 29 if Pos(LookText, UpperCase(ListView1.Items[X].Caption)) <> 0 then 30 begin 31 Found := True; 32 ListView1.Selected := nil; 33 ListView1.Selected := ListView1.Items[X]; 34 ListView1.Items[X].MakeVisible(False); 35 ListView1.SetFocus; 36 end; 37 X := X + Adder; 38 end; 39 until 40 (X > MaxLines) or (Found) or (X < 0); 41 end; 42 if Found = False then 43 begin 44 SoundBeep; 45 end; 46 end;