龙人在线
about me

Arron

抛砖只为引玉(QQ长期隐身在线)
不能富贵难成大器皆因懒,
胸无大志庸庸碌碌只为闲。

这里是我平时收集的和写的一些东西,希望和大家一起共同进步!

无聊看看电影 边听音乐边看 有空多交流
Google_search
Google
hot
latest
photos
还你真实的开幕式!震撼美图[转]【连载】 央行今日发行600万张面额10元奥运纪念钞(组图) 巧遇日本妹妹海滩拍片片 诱不可挡超级丰胸大美人
links
龙人在线 >> 学习资料 >> Delphi专栏 >> 如何使dbgrid中不同的值显示不同颜色

如何使dbgrid中不同的值显示不同颜色

来源:来自网络 作者:不详 日期:2010-01-27 热度:

在DBGrid的OnDrawDataCell事件下写:
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
  if Table1.FieldByName('partno').AsFloat > 2500 then
  DBGrid1.Canvas.Brush.Color := clGreen;
  //DBGrid1.Canvas.Font.Color := clRed;
  DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;

或(注意是"或")在OnDrawColumnCell下写:

二者的区别是OnDrawDataCell必须是Columns属性为csDefault,既为空。而OnDrawColumnCell没这个要求。

procedure TForm_cost.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  with DBGrid1 do
    begin
      if ((State = [gdSelected]) or (State=[gdSelected,gdFocused]))     then
      begin
        Canvas.Font.Color :=clLime;
        Canvas.Brush.Color :=clMaroon;
      end
    else
      if Table1.FieldByName('Salary').AsFloat < 40000 then
begin
canvas.Font.Color := clYellow;
canvas.Font.Style := [fsItalic];
Canvas.brush.Color := clGreen;
end
else
begin
canvas.Font.Color := clNavy;
Canvas.Font.Style := [fsBold];
Canvas.brush.Color := clRed;
end;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
//DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

Tags: IE
广告位招租,广告代号:gg468
search
站内
advertise
Copyright © www.jx19.Com All rights reserved.