I'm trying to display an empty text for a TDBGrid
's cell without changing the field's value neither the backcolor of the cell.
I'm not sure it's the right approach but I've tried using the OnDrawDataCell
event as follows:
procedure TMyForm.MyGridDrawDataCell(Sender: TObject;
const Rect: TRect; Field: TField; State: TGridDrawState);
var
Grid : TDBGrid;
begin
inherited;
if(Field.FieldName = 'MYFIELD') then
begin
Grid := Sender as TDBGrid;
Grid.Canvas.FillRect(Rect);
end;
end;
After placing a breakpoint into the event, I've noticed that it's never executed
Resolved using OnDrawColumnCell
event handler instead of the obsolete OnDrawDataCell
As documentation says:
Do not write an OnDrawDataCell event handler. OnDrawDataCell is obsolete and included for backward compatibility. Instead, write an OnDrawColumnCell event handler.