用DBGridEh設定了多表頭,改變了Title的Color后,多表頭的第一行背景色沒有變化(如圖),該如何處理
uj5u.com熱心網友回復:
沒人會嗎?

uj5u.com熱心網友回復:
樓主沒圖,不明白你的需求。網上搜的常用改顏色代碼。
procedure TForm25.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
with DBGridEh1 do
begin
if (Rect.Top = DBGridEh1.CellRect(DBGridEh1.Col, DBGridEh1.Row).Top) and (not
(gdFocused in State) or not DBGridEh1.Focused) then begin
//and之前的一句表示當前行,把=改為 <> 就是除了當前行的所有行
//and之后那句表示如果不是輸入焦點或者DBGridEh沒有得到焦點,也就是說當沒有選中DBGridEh時,
//當前行變色,選中時,當前行除了選中單元格以外的單元格變色
DBGridEh1.Canvas.Brush.Color := clSkyBlue;
//Current background color of the Windows desktop
end else begin
if self.ADOQuery2.FieldByName('是否批示').AsBoolean then
begin
canvas.Font.Color := clWindowText;
canvas.Font.Style := [];
Canvas.brush.Color := clRed;
end
end;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;
procedure TForm1.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
with DBGridEh1 do
begin
if (gdSelected in State) or (gdFocused in State) then
begin
if (DataSource.DataSet.FieldByName('status').AsInteger =201) then begin
Canvas.Font.Style := [];
Canvas.Font.Color :=clLime;
Canvas.Brush.Color :=clMaroon;
end;
end
else
if (DataSource.DataSet.FieldByName('status').AsInteger =201) then
begin
canvas.Font.Color := clNavy;
Canvas.Font.Style := [];
Canvas.brush.Color := clRed;
end
else
begin
canvas.Font.Color := clWindowText;
canvas.Font.Style := [];
Canvas.brush.Color := clWhite;
end;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
//DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
如何實作在DbgridEh中不同的行顯示不同的顏色
發布時間:2006.08.15 20:47 來源:plwww 作者:
【實作 DBGridEh 隔行分色顯示】
procedure TForm1.DBGridEh1GetCellParams(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState);
begin
if DBGridEh1.SumList.RecNo mod 2 = 1 then
Background := $00FFC4C4
else
Background := $00FFDDDD;
end;
【DBGridEh 在某些條件下某行顯示特定顏色】
procedure TForm1.DBGridEh1GetCellParams(Sender: TObject; Column: TColumnEh; AFont: TFont; var Background: TColor; State: TGridDrawState);
begin
//在 name 欄位值為 aaa 的行設定行背景色(ado 設定情況下)
if ADOQuery1.FieldByName('name').AsString = 'aaa' then
Background := $00FFC4C4
//在 xm 欄位值為 Li ming 的行設定行背景色(bde 設定情況下)
else if DBGridEh1.DataSource.DataSet.FieldByName('xm').AsString = 'Li ming' then
Background := $00FFC4C4
else
Background := $00FFDDDD;
end;
樓主可下載這個說明研究研究:
http://download.csdn.net/detail/wozengcong/5510871
uj5u.com熱心網友回復:
DBGridEh.FixedColor 的屬性就可以轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/122360.html
標籤:VCL組件開發及應用
上一篇:Delphi輸出字母表
