想要实现双击一行改变其颜色,当行移动后,其颜色不变,等再双击此行,去掉颜色,不怎么会用cxgrid,请教高手该如何写代码?谢谢

解决方案 »

  1.   

    我的想法是先在数据库中存一个标示字段,双击时设为True,再双击改为False;然后在GetContentStyle中根据这个值改变颜色
    下面是在网上找的一个例子和我做过的程序
    var
    AYellowStyle: TcxStyle;procedure TForm1.FormCreate(Sender: TObject);
    begin
    //行颜色
    AYellowStyle := TcxStyle.Create(Self);
    AYellowStyle.Color := $0080FFFF;
    AYellowStyle.TextColor := clMaroon;
    end;procedure TForm1.cxGrid1DBBandedTableView1StylesGetContentStyle(
    Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
    AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    begin
    if ARecord.Values[cxGrid1DBBandedTableView1Lengthcm.Index] < 81 then
    AStyle := AYellowStyle;
    end;procedure TfrmModifyQueryInvertory.cxGridDBQueryStylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    var
      N:Integer;
      ADisplayStyle :TcxStyle;
    begin
      inherited;
      N :=cxGridDBQuery.GetColumnByFieldName('ProfitMark').Index;
      ADisplayStyle :=TcxStyle.Create(Self);
      try
        if ARecord.Values[N]='盘盈' then
        begin
          ADisplayStyle.Color :=clYellow;
          ADisplayStyle.Font.Color :=clBlack;
          AStyle :=ADisplayStyle;
        end else
        if ARecord.Values[N]='盘亏' then
        begin                                             
          ADisplayStyle.Color :=clRed;
          ADisplayStyle.Font.Color :=clBlack;
          AStyle :=ADisplayStyle;
        end;
      finally
        ADisplayStyle.Free;
      end;