//'SOME_INTEGER_FIELD' is the database field name for the
//desired column.
if Column.FieldName = 'SOME_INTEGER_FIELD' then
aString := IntToStr(Column.Field.AsInteger);
if (Column.FieldName = 'ID_GROUP') then
begin
dbgrPERFIL.Canvas.FillRect(Rect);
dbgrPERFIL.Canvas.TextOut(Rect.Left, Rect.Top,
RETURNGROUP(Column.Field.AsInteger));
end
else
begin
dbgrPERFIL.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
"Richard Gilbert" <rag...@bellsouth.net> escreveu na mensagem
news:3E934EB0...@bellsouth.net...
> I4m using a dbgrid that has a integer field.
It may be a better idea to use TField.OnGetText and OnSetText and do
the transformation (and its reverse) there. This way the field could be
made editable too. If you use OnDrawColumnCell, when the user invokes
the grid's editor for that field the integer value will be displayed
instead of the transformed string.
I tend to agree with that, though there are occasions when you might want the
display in a grid to be different from the display of the same field in an
edit, for instance, in which case the Set/GetText approach becomes too
constraining. Suppose you want to display a boolean in a grid as a checkmark
and as True/False in an Edit, here the OnDrawColumnCell is useful. To
overcome the InplaceEditor popping-up when editing the checkmark the Grid's
ReadOnly property can be set in the OnColumnEnter event leaving you free to
draw as you wish.
--
Regards,
Chris Luck.
--
Robert Cerny
http://codecentral.borland.com/codecentral/ccWeb.exe/author?authorid=18355
> I tend to agree with that, though there are occasions when you might
> want the display in a grid to be different from the display of the
> same field in an edit,
Yes.
> for instance, in which case the Set/GetText
> approach becomes too constraining. Suppose you want to display a
> boolean in a grid as a checkmark and as True/False in an Edit, here
> the OnDrawColumnCell is useful.
In this case creating a TDBGrid descendant that displays checkboxes for
boolean fields would be worth the effort.
> To overcome the InplaceEditor
> popping-up when editing the checkmark the Grid's ReadOnly property
> can be set in the OnColumnEnter event leaving you free to draw as you
> wish.
That's one way of doing it. The other (if you do implement a
descendant) is to override CanEditShow (IIRC) and return False for
boolean fields.
> (if you do implement a descendant)
I'll get around to it one of these days. :)
--
Regards,
Chris Luck.