Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
ow to search for text in a TListView item Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
31-Oct-02
Category
VCL-General
Language
Delphi 2.x
Views
80
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to search for text in a TListView item

Answer:

Parameters:

lv:
The listview, supposed to be in vaReport mode

S:
The text to search for

Column:
The column index for the column to search , 0-based. Returns the found listview 
item,
or Nil if none was found

Precondition:
lv <> nil, lv in report mode if column > 0, S not empty

Description:
The search is case-insensitive and will only match on the complete column content. 
Use
AnsiContainsText instead of AnsiCompareText  to match on a substring in the columns 
content.
1   
2   function FindListviewItem(lv: TListview; const S: string; column: Integer): 
3   TListItem;
4   var
5     i: Integer;
6     found: Boolean;
7   begin
8     Assert(Assigned(lv));
9     Assert((lv.viewstyle = vaReport) or (column = 0));
10    Assert(S <> '');
11    for i := 0 to lv.items.count - 1 do
12    begin
13      result := lv.Items[i];
14      if column = 0 then
15        found := AnsiCompareText(result.caption, S) = 0
16      else if column <= result.subitems.count then
17        found := AnsiCompareText(result.subitems[column - 1], S) = 0
18      else
19        found := false;
20      if found then
21        Exit;
22    end;
23    {No hit if we get here}
24    Result := nil;
25  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC