如题,想要在Button1按下的时候使得ListView中的某一个Item的字体变粗,或者改变字体的颜色等,应该如何做?

解决方案 »

  1.   

    下面的代码能够让你设定所有串为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;