我用stringgrid控件,还有一个edit控件,实现用edit控件作为数据录入的空间,即选择一个单元格,然后edit控件setbound,然后输入数据,当edit控件离开这个单元格时stringgrid.cell[i,j]:=edit1.text;我现在想根据一定的条件来判断某个单元格只读,最好是这个edit控件不能贴在只读的单元格中,直接跳到下一个可编辑的单元格中。

解决方案 »

  1.   

    procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    begin
      if(ACol = 2) then  //第二列不可选
        CanSelect := False;
      if (ACol = 1) and (ARow = 2) then  //第一列第二行不可选
        CanSelect := False;
    end;
      

  2.   

    if (StringGrid1.Row in [2,3])   then
    if StringGrid1.Col in [2,3] then
      

  3.   

    为什么要edit控件?
    StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
    begin
      //前三列只读.
      if ACol > 3 then
        StringGrid1.Options:=StringGrid1.Options + [goEditing]
      else
        StringGrid1.Options:=StringGrid1.Options - [goEditing]
      CanSelect:=true;
    end;