读书人

listview如何设置某个单元格的颜色

发布时间: 2012-03-09 16:54:56 作者: rapoo

listview怎么设置某个单元格的颜色
Listview有多列数据,每列数据是在一定的范围内,如果某行数据的某个字段值不在范围内则将该单元格的数据设置为红色字体,否则为黑色字体

[解决办法]
procedure Form.ListView2CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin

if (Item.SubItems.Strings[1])>3 then
begin
Sender.Canvas.Brush.Color := clRed;
Sender.Canvas.Font.Color := clYellow;
end;
end;
[解决办法]

Delphi(Pascal) code
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;  Item: TListItem; SubItem: Integer; State: TCustomDrawState;  var DefaultDraw: Boolean);begin  if SubItem=1 then    self.ListView1.Canvas.Font.Color:=clRed;  else    Self.ListView1.Canvas.Font.Color:=clBlue;  end;end; 

读书人网 >.NET

热点推荐