procedure TFrm_MainForm.tbDBPartResultStylesGetContentStyle( Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle); begin if ARecord.Values[0] = 0 then //判断N的值 AStyle := AGreenStyle; if ARecord.Values[0] = 1 then AStyle := AYellowStyle; if ARecord.Values[0] = 2 then AStyle := ARedStyle; end;
加一个cxStyleRepository1控件,设置好几个颜色 分别命名为cxStyle1,cxStyle1procedure TForm1.cxGrid1DBTableView1StylesGetContentStyle( Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle); begin if ARecord.Values[0] ='N' then AStyle := cxStyle1 else AStyle := cxStyle2; end;
稍改一下:因为你的TcxGridDBTableView继承自TcxCustomGridTableView,所以进行一下向下转型 procedure TFrmExpense.Contvew_MStylesGetContentStyle( Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle); begin if ARecord is TcxGridDataRow then begin if Sender.DataController.GetDisplayText(ARecord.Index,TcxGridDBTableView(Sender).DataController.GetItemByFieldName('status').Index)='已报' then AStyle := DMImpl.cxStyle18; end; end;
cxGrid1DBTableView1.FindItemByName('cxGrid1DBTableView1statusid').Index //连接列名 ARecord.Values[cxGrid1DBTableView1.GetColumnByFieldName('N').Index] ='1' then //连接字段名procedure TForm1.cxGrid1DBTableView1StylesGetContentStyle( Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle); begin if ARecord.Values[cxGrid1DBTableView1.GetColumnByFieldName('N').Index] ='1' then AStyle := cxStyle1 else AStyle := cxStyle2;end;
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
if ARecord.Values[0] = 0 then //判断N的值
AStyle := AGreenStyle;
if ARecord.Values[0] = 1 then
AStyle := AYellowStyle;
if ARecord.Values[0] = 2 then
AStyle := ARedStyle;
end;
分别命名为cxStyle1,cxStyle1procedure TForm1.cxGrid1DBTableView1StylesGetContentStyle(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
if ARecord.Values[0] ='N' then
AStyle := cxStyle1
else
AStyle := cxStyle2;
end;
http://www.delphifans.com/infoView/Article_722.html
procedure TFrmExpense.Contvew_MStylesGetContentStyle(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
if ARecord is TcxGridDataRow then
begin
if Sender.DataController.GetDisplayText(ARecord.Index,TcxGridDBTableView(Sender).DataController.GetItemByFieldName('status').Index)='已报' then
AStyle := DMImpl.cxStyle18;
end;
end;
ARecord.Values[cxGrid1DBTableView1.GetColumnByFieldName('N').Index] ='1' then //连接字段名procedure TForm1.cxGrid1DBTableView1StylesGetContentStyle(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
if ARecord.Values[cxGrid1DBTableView1.GetColumnByFieldName('N').Index] ='1' then
AStyle := cxStyle1
else
AStyle := cxStyle2;end;