cxGrid控件以cxGridDBCardView视图显示,记录集中有字段a和b,cxGridDBCardView中只显示a,但希望a的颜色能以b的值的不同而不同,请教各位大侠.
    给出各对象名称,便于大家回复:
    表格控件:cxGrid1
    表格中视图:cxGridDBCardView1
    视图中的列:cxGrid2DBCardView1Row1  与字段a绑定
    记录集:adodataset1
    b的值:[1,2,3,4,5,6,7]
    

解决方案 »

  1.   

    这需要在onCustomDrawCell编写事件,根据b的值进行处理。cxgrid自带的示例中有这样的例子。
      

  2.   

    procedure TFQueryBuilding.cxGrid2DBCardView1StylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    var
      ADisplayStyle: TcxStyle;
    begin
      if trim(vartostr(ARecord.Values[1])) = 'a' then
      begin
        ADisplayStyle := TcxStyle.Create(Self);
        ADisplayStyle.Color := RGB(96, 186, 3);
        ADisplayStyle.Font.Color := RGB(255, 255, 255);
        AStyle := ADisplayStyle;
      end
      else if trim(vartostr(ARecord.Values[1])) = 'b' then
      begin
        ADisplayStyle := TcxStyle.Create(Self);
        ADisplayStyle.Color := RGB(96, 166, 234);
        ADisplayStyle.Font.Color := RGB(255, 255, 255);
        AStyle := ADisplayStyle;
      end;  end;
      

  3.   

    zhubaiming  的解答应该可以