请教高手,如何在DBGRID中对某一Column进行重画,其内容包括用不同颜色表示的分隔线?主要是想实现类似于会计帐本里的对金额的分隔一样。

解决方案 »

  1.   

    你想重画什么,图象还是什么,给你个我写的以前的代码例子
    procedure Tfrm_main.dbgmainDrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
    if ((sender as Tdbgrid).DataSource.DataSet.IsEmpty) or (not (sender as Tdbgrid).DataSource.DataSet.Active) then exit;
    if Column.FieldName = 'RecNo' then
      begin
       with Sender as TDBGrid do
          begin
          Canvas.Font.Color:=clRed;
          canvas.Brush.Color:=clwhite;
          canvas.fillrect(rect);
          Canvas.TextRect(Rect,rect.Left+17,Rect.Top+2,inttostr(qry_main.RecNo));
        end;
      end;
    if Column.FieldName = 'RWSWJM' then
      begin
       with Sender as TDBGrid do
          begin
          Canvas.Font.Color:=clblue;
          canvas.Brush.Color:=clwhite;
          canvas.fillrect(rect);
          if qry_main.FieldByName('RWSWJM').AsString<>'' then
          Canvas.TextRect(Rect,rect.Left+8,Rect.Top+2,'★');
        end;
      end;
    end;
      

  2.   

    用SNC控件来实现,自己画是不能很好达到想要的效果的
      

  3.   

    用SNC控件吧,自己画是不能很好达到想要的效果地
      

  4.   

    procedure TfmStoreOut.DBGrid1DrawColumnCell(Sender: TObject;
    const Rect: TRect; DataCol: Integer; Column: TColumn;
    State: TGridDrawState);
    beginif gdSelected in State then
       exit;if SQLClientDataSet.RecNo mod 2 = 0 then
       DBGrid1.Canvas.Brush.Color := clRed;
    else
       DBGrid1.Canvas.Brush.Color := clBlue;DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
      

  5.   

    请教weizi2000(秋风啊) ,你说的SNC控件哪里可以下载到呀?谢谢。
      

  6.   

    怎樣設置ADOQUERY數據集是可讀和可寫
      

  7.   

    不要用什么控件
    DBGRID的DrawColumnCell事件都能达到你的目的
    单元格
    某行
    某列
    分隔线
    等等
    都可以的
      

  8.   

    procedure TfmStoreOut.DBGrid1DrawColumnCell(Sender: TObject;
    const Rect: TRect; DataCol: Integer; Column: TColumn;
    State: TGridDrawState);
    beginif gdSelected in State then
       exit;if SQLClientDataSet.RecNo mod 2 = 0 then
       DBGrid1.Canvas.Brush.Color := clRed;
    else
       DBGrid1.Canvas.Brush.Color := clBlue;DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
    ==========================================
    正确,这里多了