首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

cxgird满足条件的纪录的着色有关问题

2012-02-09 
cxgird满足条件的纪录的着色问题先看代码:procedure TForm1.cxGrid1DBTableView1CustomDrawCell(Sender: T

cxgird满足条件的纪录的着色问题
先看代码:

procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  //取得今天的日期放到edit1.text里面
  edit1.Text :=datetostr(date);
  //将cxgrid中纪录中 日期=今天 的纪录整行文字设置为红色,日期不是今天的纪录设置为黑色。
  //就是说把日期是今天的纪录着红色显示出来
  if cxgrid1dbtableview1.DataController.DataSource.DataSet.FieldByName('日期').AsString =edit1.Text then
  ACanvas.Canvas.Font.Color:=clRed
  else
  ACanvas.Canvas.Font.Color:=clblack;
end;

但是有问题,不能按我想的出结果。一显示首先所有纪录的文字都是红色(日期=今天的纪录在第一条),点日期不是今天的一条纪录颜色变黑色(连同日期是今天的纪录也变成了黑色),点日期是今天的一条纪录后,此纪录文字变为红色,但刚才点的那条日期不是今天纪录也变成红色。高手请帮忙看一下,到底怎么回事?


[解决办法]
你很搞哦,你每次判断条件都是当前记录和你的时间做比较,比较完了当然是所有都刷新了。

改成判断cell里面的字符和你的edit1里的字符做比较,不要用数据库里的当前记录的日期值,你现在成了用一个字符和一个全局变量做比较了,当然不对。用AViewInfo.Text和edit1.Text比较。如果你的其他没有错误的话。
[解决办法]
在 onGetContentStyle事件中处理,用这个控件StyleRepository去定义不同的style
procedure TFrmItemInfo.Contvew_MStylesGetContentStyle(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
if ARecord is TcxGridDataRow then
begin
if (ARecord.Values[1] = edit1.Text) then
AStyle := cxStyle18;
else
AStyle := cxStyle46;
end;
end;


[解决办法]

探讨
在 onGetContentStyle事件中处理,用这个控件StyleRepository去定义不同的style
procedure TFrmItemInfo.Contvew_MStylesGetContentStyle(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGri……

热点排行