怎么显示成这样?
    我的意思:现在的grid的横线只有两种选择,要么全有,要么全不显示,我想知道能不能根据数据的情况分组显示,也就是隔几行在显示一个横线,当然间隔行不是一个确定的数,而应该根据数据而定!

解决方案 »

  1.   

    grid的draw属性设成自己画,
    OndrawCell 
      

  2.   

    例子给出来了,你需要自己在ONDRAWCELL里处理数据的组,然后看下面的东西就行了。unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Grids;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        Button1: TButton;
        procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
          Rect: TRect; State: TGridDrawState);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      case ARow of
       3,5,10:begin
         With StringGrid1 do begin
          if Cells[ACol,Arow]<>'' then begin
           Canvas.MoveTo (Rect.left,Rect.Top);
            Canvas.LineTo (rect.right,rect.top);
          end;
          end;
        end;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
    With StringGrid1 do begin
        for i:=0 to  17 do begin
          RowCount:=RowCount+1;
         Cells[0,i]:=inttostr(i);
        end;
      end;
    end;end.
      

  3.   

    要在GRID中画出不确定的直线,可应用OWENERDRAW。然后在GRID的ONDRAWCELL事件中,根据传入的行列不同,画出直线,当然,也可在此事件中对表格单元设置颜色,画图片等操作。
    要TDRAWGRID中有几个函数可能有用:
    function CellRect(ACol, ARow: Longint): TRect;
    procedure MouseToCell(X, Y: Integer; var ACol, ARow: Longint);
    在获取单元的坐标后,就可应用CANVAS任意作图了。
      

  4.   

    遍历数据时,在适当的地方加入横线即可。(使用Canvas的方法与属性)。
      

  5.   

    我用的是aligngrid,ondrawcell有问题,当有横向滚动时,屏幕的线就乱拉,还在修改中
    不过先把分分了,椅子鼓励  :-)