在dbGrid的OnDrawDataCell事件上写上代码就行了,如:
if tbTradeDecUDR.IsNull then Exit;
with TDBGrid(Sender).Canvas do
begin
R := Rect;
R.Left := 0;
R.Right := 0;
LeftOffset := 0;
with TDrawGrid(Sender) do
for i := 0 to ColCount - 1 do
begin
if i = LeftCol then LeftOffset := R.Right;
Inc(R.Right, ColWidths[i]);
end;
OffsetRect(R, -LeftOffset, 16);
Font.Style := [fsBold];
Font.Color := clNavy;
Brush.Style := bsClear;
S := 'UDR: ' + tbTradeDecUDR.AsString;
TextOut(4, R.Top, S);
Font.Color := clBlack;
TextOut(10 + TextWidth(S), R.Top, tbTradeDecConsignee.AsString);
Font.Color := clBlue;
S := tbTradeDecTotal.DisplayText;
TextOut(R.Right - TextWidth(S) - 6, R.Top, S);
end;