下面的代码能够让你设定所有串为Edit1.Text值的Item字体改变。包括Caption和SubItem都会变。
var
Form1: TForm1;
strPos:string;
implementation
{$R *.dfm}
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
if Item.SubItems[SubItem-1]=strPos then
begin
ListView1.Canvas.Font.Color:=clred;
ListView1.Canvas.Font.Style:=[fsBold];
end else
ListView1.Canvas.Font.Color:=clBlack;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
strPos:=Edit1.Text;
ListView1.Refresh;
end;
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if Item.Caption=strPos then
begin
ListView1.Canvas.Font.Color:=clred;
ListView1.Canvas.Font.Style:=[fsBold];
end else
ListView1.Canvas.Font.Color:=clBlack;
end;