0

Previously with the default DBGrid I could alter the value of a cell without altering the data in a database with the following code.

procedure TEMRForm.DBGridCDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if Column.FieldName = 'START_DATE' then
  begin
    DBGridC.Canvas.FillRect(Rect);          
    DBGridC.Canvas.TextOut(Rect.Left+2,Rect.Top+2,Column.Field.Text + ' *');
  end;
end;

Which worked great, but I am having trouble implementing this same kind of functionality on a cxgrid. Here is my current code which shows no indication of the cell value being changed.

procedure TEMRForm.cxGridCDBTableView1CustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
ARect: Trect;
begin
  ARect := AViewInfo.Bounds;
  if AViewInfo.Item.Caption = 'Start Date' then
  begin
    ACanvas.FillRect(ARect);
    ACanvas.TextOut(ARect.Left+2,ARect.Top+2,TableC.FieldByName('START_DATE').AsString+' *');
  end;
end;
Trevor
  • 16,080
  • 9
  • 52
  • 83

1 Answers1

2

I think the reason why you don't see the drawning done in cxGridCDBTableView1CustomDrawCell() is because you don't set the ADone parameter to true - thus the default painting will "cancel" (overpaint) your's.

However, I think the right way to achieve what youre after is to use column's events OnGetDisplayText and OnGetContentStyle (the later event is subproperty of Styles, ie Column.Styles.OnGetContentStyle).

ain
  • 22,394
  • 3
  • 54
  • 74
  • Thanks that worked, but good point about using the column events.. Do you foresee any issues with doing it on the drawcell event? – Trevor Sep 27 '12 at 19:11
  • I think the column events are more future proof but in simple case drawcell should be ok too. – ain Sep 27 '12 at 19:18
  • So this works but what I'm finding is that the table and or associated dataset with the cx grid is not changing records based on the records being populated in the grid. So its still not working like it did with the other grid. I'll look into it. Thanks – Trevor Sep 27 '12 at 20:25