在 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;
TO mysterx:procedure TForm1.cxGrid1DBTableView1CustomDrawCell( Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); begin //取得今天的日期放到edit1.text里面 edit1.Text :=datetostr(date); //下面一句判断代码改好了 if aviewinfo.Text =edit1.Text then ACanvas.Canvas.Font.Color:=clRed else ACanvas.Canvas.Font.Color:=clblack; end;这样执行一下,确实OK了。 但是只有符合条件的这一个日期字段变红色。我想这个日期字段所在的整条纪录都变红色,该咋办呢? 盼指教!
这个使用DBGRID控件显示的,代码如下,没有任何问题。符合条件的整行的文字都变成了红色。 procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin edit3.Text :=dbgrid1.DataSource.DataSet.FieldByName('日期').AsString; edit1.Text :=datetostr(date); //满足条件的变红色(字的颜色变红色) //TO mysterx:为什么下面这样写能行呢? if dbgrid1.DataSource.DataSet.FieldByName('日期').AsString=edit1.Text then begin DBGrid1.Canvas.Font.Color := clRed; DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State); end end;
http://topic.csdn.net/u/20071111/20/649F1BD8-920A-4EBE-B666-D9EF397AB66C.html
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;
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
//取得今天的日期放到edit1.text里面
edit1.Text :=datetostr(date);
//下面一句判断代码改好了
if aviewinfo.Text =edit1.Text then
ACanvas.Canvas.Font.Color:=clRed
else
ACanvas.Canvas.Font.Color:=clblack;
end;这样执行一下,确实OK了。
但是只有符合条件的这一个日期字段变红色。我想这个日期字段所在的整条纪录都变红色,该咋办呢?
盼指教!
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
edit3.Text :=dbgrid1.DataSource.DataSet.FieldByName('日期').AsString;
edit1.Text :=datetostr(date);
//满足条件的变红色(字的颜色变红色)
//TO mysterx:为什么下面这样写能行呢?
if dbgrid1.DataSource.DataSet.FieldByName('日期').AsString=edit1.Text then
begin
DBGrid1.Canvas.Font.Color := clRed;
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end
end;
阿三的方法。
建议不要使用StringGrid的方法。
这句改成ACanvas.Font.Color:=clRed,就可以了
else
ACanvas.Canvas.Font.Color:=clblack;
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
{参数 Sender: 你要实现特效的TableView;
ACanvas: 画布, 这个参数比较重要, 就是用这个参数画出特效;
AViewInfo: 自定义条件的来源; 从这个参数中获取单元格值;
ADone: 设为真就不会Paint. }
begin
edit1.text=datetostr(date);
if AViewInfo.GridRecord.Values[3]=edit1.text then
{AViewInfo.GridRecord.Values[3]:取得某一列(3是代表第四列,我的程序里面第四列是日期的字段)中的单元格的数据。}
//ACanvas.Brush.Color := clred;//背景色改变
ACanvas.Font.Color:=clred;//字体颜色改变
end;这样,在日期字段中所有等于今天的纪录的字体变红色,整条纪录都变成了红色,而不只是日期字段单元格变色。