这是我从一个软件拿的例子,好好看看吧
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
OldColor, OldFontColor: TColor;
begin
if CheckCurrencyField(Column.FieldName) then
begin
if (gdFocused in State) then
begin
sncDBCurrencyInplaceEdit.Left := Rect.Left + DBGrid1.Left+2;
sncDBCurrencyInplaceEdit.Top := Rect.Top + DBGrid1.top+2;
sncDBCurrencyInplaceEdit.Width := Rect.Right-Rect.Left;
sncDBCurrencyInplaceEdit.Height := Rect.Bottom- Rect.Top;
SetHighLightColor;
if (sncDBCurrencyInplaceEdit.Tag=1) and not sncDBCurrencyInplaceEdit.Visible then
sncDBCurrencyInplaceEdit.Visible := True;
end
else
begin
OldColor := sncDBCurrencyInplaceEdit.Color;
OldFontColor := sncDBCurrencyInplaceEdit.Font.Color;
SetNormalColor;
DrawCurrencyFrame(DBGrid1.Canvas, Rect, sncDBCurrencyInplaceEdit, Column.Field.AsFloat);
sncDBCurrencyInplaceEdit.Color := OldColor;
sncDBCurrencyInplaceEdit.Font.Color := OldFontColor;
end;
end;
end;