上述代碼執行的功能是:把薪水超過3萬6千元的員工(employee)記錄背景用白色(White)標出來。
圖三
第3種 如何改變指定列中某些單元格的背景色,代碼如下:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if Table1.FIEldByName('Salary').AsCurrency>40000 then
begin
DBGrid1.Canvas.Font.Color:=clWhite;
DBGrid1.Canvas.Brush.Color:=clBlack;
end;
if DataCol = 4 then
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
上述代碼執行的功能是:把薪水超過4萬的員工(employee)記錄背景用黑色(White)標出來而文本用白色標出來。
就是這樣方便,因為你使用的是Delphi,這句像在為Borland作廣告了,呵呵,我的程序在Delphi7+Winxp和Delphi+Windows2000上編譯通過,大家不妨一試。