1.插入、删除。不知道有没有不需要一行行搬的办法。这是顺手问问。2.初始化表头:
好像StringGrid不像DBGrid那样可以在设计时定义表头,如果可以请告诉我怎么做,就更好了。如果在运行期处理表头,我想在构造函数那个部分,执行原构造函数后做表头的处理。
请问,这个办法时候可行?有什么缺点,有什么更好的办法?
如果这个办法可行,是不是需要完全手工写构造函数(好像不能像OnClick那样自动生成函数头)?敬请指教,谢谢。

解决方案 »

  1.   

    关于第一个问题,你可以用数组来解决
    第二个问题:如果标头没有一定规律的话,当然是手工写代码了
    procedure TForm.FormCreate(Sender: TObject);
    begin
    with StringGrid do
    begin
    RowCount:=10;
    ColCount:=2;
    Cells[0,0]:='s';
    Cells[1,0]:='d';
    end;
    end;
      

  2.   

    谢谢。
    关住使用数组的解决办法,能说的详细点吗?对于第二个问题。可能我没说清楚我的问题。
    您是在TForm.FormCreate里完成的,而我想问的是“是否可以重载StringGrid的构造函数完成”。
    而我所说的手写,是指,如果利用重载构造函数的方法完成,那么,函数头好像无法用IDE自动生成,应该是需要手写的吧?
      

  3.   

    不需要重载StringGrid,StringGrid有个OnDrawCell 事件 可以自定义单元格!
      

  4.   

    嗯,谢谢。我几乎是在线等了。表格文字居中什么,我是放在OnDrawCell里了。那个地方是控制表格内容的。
    构造函数那个地方,我是想把写表头的那个部分放过去。就是写Fixed Row的内容的那一段。其实也不一定要放到构造函数里,在Form的OnCreate里处理似乎是更常用的方法。不过就是忽然冒出这么个想法来,想在这里请教一下是否可行,有什么区别,呵呵。今天到这里睡,明天再来提前贴子可指点。
      

  5.   

    表头你可以像俺兄弟hsmserver(撒哈拉之雨的悲伤)说的做,很多属性可以Option设置的
    你要别的就要在里面画了,下面这个是回车换行
       if key = 13 then begin
           if StringGrid1.Row<StringGrid1.RowCount-1 then
               StringGrid1.Row := StringGrid1.row+1;
       end;
      

  6.   

    StringGrid行列的增加和删除
    ========================== 
    type
     TExCell = class(TStringGrid)public
     procedure DeleteRow(ARow: Longint);
     procedure DeleteColumn(ACol: Longint);
     procedure InsertRow(ARow: LongInt);
     procedure InsertColumn(ACol: LongInt);
    end;procedure TExCell.InsertColumn(ACol: Integer);
    begin
     ColCount :=ColCount +1;
     MoveColumn(ColCount-1, ACol);
    end;procedure TExCell.InsertRow(ARow: Integer);
    begin
     RowCount :=RowCount +1;
     MoveRow(RowCount-1, ARow);
    end;procedure TExCell.DeleteColumn(ACol: Longint);
    begin
     MoveColumn(ACol, ColCount -1);
     ColCount := ColCount - 1;
    end;procedure TExCell.DeleteRow(ARow: Longint);
    begin
     MoveRow(ARow, RowCount - 1);
     RowCount := RowCount - 1;
    end;