cxgrid几种条件下行变色问题与解决

来源:互联网 发布:恋恋影视vip2账号淘宝 编辑:程序博客网 时间:2024/06/06 01:02

cxgrid几种条件下行变色问题与解决

1 .鼠标选中行变色。

其实默认条件下,鼠标选中的行就会变色,但是被点中的单元格不变色,如果想让单元格和其它列一样的话,在cxGrid1DBTableView中找属性OptionsSelection中的CellSelect的属性变成False.但是默认颜色可能达不到使用者的要求,比如有粉粉控的人只喜欢粉色,想让选中的行变成粉色怎么办呢?很简单,只需要使cxStyleRepository控件在styles中加一种颜色就可以了。效果如图
这里写图片描述

2 .焦点不再cxgrid表中但数据库中数据对应的行变颜色。

方法有很多,我只说一种,原理是利用数据库中所指的当前行数据,然后对应到cxgrid表上。

procedure TForm1.cxGrid1DBTableView1CustomDrawCell(  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);beginif iewinfo.RecordViewInfo.Index=cxGrid1DBTableView1.Da  taController.GetFocusedRowIndex thenacanvas.Brush.Color:=clgreen;end;

Item确定列(ID列的索引),RecordViewInfo确定行(Index行的索引)

可以定位到某一行改变颜色

if (AViewInfo.Item.ID = 0) //0列
if (AViewInfo.RecordViewInfo.Index = 0) //0行

3 .固定某行按条件变色

procedure TForm1.cxGrid1DBTableView1CustomDrawCell(  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);  if (AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('SheBeiBianHao').Index])='20050419' then  begin   ACanvas.Brush.Color := clRed;  end;
1 0