【问题标题】:How can I modify the text of a data base field on DrawCell? TcxGrid如何在 DrawCell 上修改数据库字段的文本? TcxGrid
【发布时间】:2012-09-27 15:05:09
【问题描述】:

以前使用默认 DBGrid,我可以更改单元格的值,而无需使用以下代码更改数据库中的数据。

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;

效果很好,但是我在 cxgrid 上实现这种相同的功能时遇到了麻烦。这是我当前的代码,它没有显示单元格值被更改的迹象。

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;

【问题讨论】:

    标签: delphi devexpress delphi-xe tcxgrid


    【解决方案1】:

    我认为您在cxGridCDBTableView1CustomDrawCell() 中看不到绘制的原因是因为您没有将ADone 参数设置为true - 因此默认绘画将“取消”(重绘)您的。

    但是,我认为实现你所追求的正确方法是使用列的事件OnGetDisplayTextOnGetContentStyle(后面的事件是样式的子属性,即Column.Styles.OnGetContentStyle)。

    【讨论】:

    • 谢谢你的工作,但是关于使用列事件的好处。你预见到在 drawcell 事件上这样做有什么问题吗?
    • 我认为列事件更具前瞻性,但在简单的情况下,drawcell 也应该没问题。
    • 所以这行得通,但我发现与 cx 网格相关联的数据集并没有根据网格中填充的记录更改记录。所以它仍然不像其他网格那样工作。我会调查的。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 1970-01-01
    • 2023-03-30
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    相关资源
    最近更新 更多