我想用不同的颜色显示tcxgrid中的一些行(取决于列值)。
我对它做了修改,但在运行我的项目后,它没有在网格上得到反映。
procedure TfrmMessaging.cxGrid1DBTableView1CustomDrawCell(..);
Var
i : Integer;
begin
For i := 0 To cxGrid1DBTableView1.ViewData.RowCount - 1 Do
Begin
If cxGrid1DBTableView1.ViewData.Rows[i].Values[4] = '1' Then
Begin
cxGrid1.Canvas.Brush.Color := clRed;
End;
End;
end;在上面的代码中,我使用了tcxgrid的cxGrid1DBTableView1CustomDrawCell事件。提前谢谢。
发布于 2014-04-02 23:35:32
如果您使用的是data-aware view (看起来是这样),则需要使用DataController而不是ViewData来访问记录。
正如TcxGridDBTableView的DevExpress帮助中所述(粗体格式是我的):
TcxGridDBTableView对象表示网格表视图的数据感知版本。除了数据绑定设置之外,它继承了它的祖先的所有功能。TcxGridDBTableView的DataController.DataSource属性提供视图与TDataSet或其后代之间的连接。
除此之外,每个单元格都会触发OnCustomDrawCell事件,因此不需要迭代行。
下面的代码应该会对您有所帮助:
procedure TfrmMessaging.cxGrid1DBTableView1CustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
if Sender.DataController.GetValue(AViewInfo.GridRecord.RecordIndex, 4) = '1' then
ACanvas.Brush.Color := clRed;
end;发布于 2014-04-03 00:16:29
通常,对于这样的东西,最简单的方法是cxStyles。将样式存储库拖放到表单上,向其添加一个或多个样式,并在对象检查器或事件处理程序(OnGetContentStyle等)中分配它们。
自定义绘图的一个优点是,样式可以用于各种计算,而所有者绘制的单元格不会被特殊处理,有时不会自动调整大小,等等。
发布于 2014-04-02 23:47:22
如何更改网格的颜色
procedure TfrmNewOffer.GrdOffDetailViewRemarkCustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
backgroundColorCode: Variant;
textColorCode: Variant;
begin
inherited;
if assigned(AViewInfo) and assigned(AViewInfo.GridRecord) then
begin
backgroundColorCode := AViewInfo.GridRecord.Values[GrdOffDetailViewBackColorCode.Index];
textColorCode := AViewInfo.GridRecord.Values[GrdOffDetailViewTextColorCode.Index];
if not VarIsNull(backgroundColorCode) then
begin
ACanvas.Brush.Color := backgroundColorCode;
end;
if not VarIsNull(textColorCode) then
begin
ACanvas.Font.Color := textColorCode;
end;
end;结束;
https://stackoverflow.com/questions/22814307
复制相似问题