大家好,我想实现一个grid中,选中某行时,这条记录其中1个列的颜色改变,形成高亮。
不知道有没有办法,先谢谢了

解决方案 »

  1.   

    当然可以了,对DataCol进行检测!procedure TErpDBGridEh.GridDrawColumnCell(Sender:TObject;const Rect: TRect; DataCol: Integer; Column: TColumnEh;
      State: TGridDrawState);
    begin
     //如果数据集没有记录,则不做操作
      try
        if not Assigned(DataSource.DataSet) then Exit;
        if DataSource.DataSet.Eof and DataSource.DataSet.Bof then exit;
        if gdSelected in State then
        begin
        //选中时
          if DataCol=2 then 
    begin 
          Self.Canvas.Brush.Color :=FSelectRowColor; //选中时颜色
          Self.canvas.Font.Color :=FSelectFontColor; //选中的字体颜色
          Self.canvas.Font.Style:=[fsBold]; //选中时的字体
    end;
        end
        else
        begin
          //没有选中时的颜色的行颜色
          if DataSource.DataSet.RecNo mod 2=0 then
            Self.Canvas.Brush.color:=FOddColor
          else
            Self.Canvas.brush.color:=FEvenColor;
        end;
      finally
         DefaultDrawColumnCell(rect,datacol,column,state);
      end; 
    end;