-
这是我自画dbgrideh的函数,其中有些地方是根据我的实际需要设的,你可以改改看
procedure TfrmCopyBook_MeterCopy.SetGridColor(var AdoTable: TDataSet; var DbGrid1: TDBGrideh; const Rect: TRect; DataCol: Integer;
Column: TColumneh; State: TGridDrawState);
begin
if (AdoTable.RecNo <> AdoTable.RecordCount + 1) and
(((DataCol >= 7) and (DataCol <= 12)) or (DataCol = 20) or (DataCol = 22)) then
DbGrid1.Canvas.Brush.color := $00EBE9A7; // file://偶数行用浅绿色显示
if ((State = [gdSelected]) or (State = [gdSelected, gdFocused])) then
case DataCol of
7, 8, 9, 10, 11, 12,20,22:
begin
DbGrid1.Canvas.Brush.color := $00FFFF; //file://当前选中行用红色
dbgrid1.Canvas.Font.Color := clred;
end;
{False:
begin
DbGrid1.Canvas.Brush.color := $00FFFF;
dbgrid1.Canvas.Font.Color := clred;
end;}
end;
DbGrid1.Canvas.pen.mode := pmCopy;
DbGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;#3得分 30
-
忘了说了,该过程在DBGridEh的DrawColumnCell事件中调用就可以了
procedure TDbgridForm.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 :=ClYellow; Canvas.Brush.Color :=ClNavy; end else begin if DataSource1.DataSet.RecNo mod 2<>0 then Canvas.brush.Color :=ClWhite else Canvas.brush.Color :=clgreen; end; DefaultDrawColumnCell(Rect, DataCol, Column, State); end; end;
引用:https://bbs.csdn.net/topics/30305871