LISTVIEW某单元格变颜色
我想让某行的某一个列变颜色,我代码如下,但是不清楚怎么的,只能让某行变颜色
procedure TFrmMainServer.ListViewServerCustomDrawItem(
  Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
if  (Trim(Sender.Column[3].Caption)='列标志') Then
Begin
  If (Item.SubItems.Strings[2]>=100 ) then  
      Sender.Canvas.Font.Color :=clYellow   
  Else
      Sender.Canvas.Font.Color :=clBlack;  //恢复原有色彩
End;
end;

解决方案 »

  1.   

    它就是不能让某列变颜色,没这项功能
    因为LISTVIEW一行算一条记录,颜色应该是统一的
      

  2.   

    //OnCustomDrawSubItem事件unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
          Item: TListItem; SubItem: Integer; State: TCustomDrawState;
          var DefaultDraw: Boolean);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);const
      Names: array[0..5, 0..1] of string = (
        ('Rubble', 'Barney'),
        ('Michael', 'Johnson'),
        ('Bunny', 'Bugs'),
        ('Silver', 'HiHo'),
        ('Simpson', 'Bart'),
        ('Squirrel', 'Rocky')
        );var
      I: Integer;
      NewColumn: TListColumn;
      ListItem: TListItem;
      ListView: TListView;
    begin
      ListView := TListView.Create(Self);
      with ListView do
      begin
        ListView.OnCustomDrawSubItem := ListView1CustomDrawSubItem;
        Parent := Self;
        Align := alClient;    ViewStyle := vsReport;    NewColumn := Columns.Add;
        NewColumn.Caption := 'Last';
        NewColumn := Columns.Add;
        NewColumn.Caption := 'First';    for I := Low(Names) to High(Names) do
        begin
          ListItem := Items.Add;
          ListItem.Caption := Names[I][0];
          ListItem.SubItems.Add(Names[I][1]);
        end;
      end;
    end;procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
      Item: TListItem; SubItem: Integer; State: TCustomDrawState;
      var DefaultDraw: Boolean);
    begin
      if (Item.Index = 1) then
        Sender.Canvas.Brush.Color := clRed
      else
        Sender.Canvas.Brush.Color := clYellow;end;end.