我想在stringgrid的单元进行文字编辑,编辑完后按enter 
使焦点自动转入相邻的下一个单元格,再进行编辑此单元格?
请提供实现代码
谢谢!

解决方案 »

  1.   

    在StringGrid的OnkeyPress写代码。
    如:
    procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      if key = #13 then 
        With StringGrid1 do
          if col < (ColCount - 1) then Col := Col + 1
          else
            if Row < (RowCount - 1) then
            begin
              Col := FixedCols;
              Row := Row + 1;
            end;
    end;
      

  2.   

    同意:支持:procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      if key = #13 then 
        With StringGrid1 do
          if col < (ColCount - 1) then Col := Col + 1
          else
            if Row < (RowCount - 1) then
            begin
              Col := FixedCols;
              Row := Row + 1;
            end;
    end;
    学习
      

  3.   

    stringGrid按enter键跳格1
    form1.keypreview :=true;2
    procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      GridRect : TGridRect;
    begin
      if key= VK_RETURN then
      begin
        if StringGrid1.Selection.Right>=  StringGrid1.ColCount-1 then
        begin
          GridRect.Left :=1;
          GridRect.Top := StringGrid1.Selection.Top+1;
          GridRect.Right:=1;
          GridRect.Bottom :=StringGrid1.Selection.Bottom+1;
          StringGrid1.Selection := GridRect;
        end
        else
          key:=VK_RIGHT;
      end;
    end;
    //------------或者
    procedure TForm1.StringGrid1KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if StringGrid1.col < StringGrid1.colCount-1 then
        StringGrid1.Col := StringGrid1.Col + 1//列向移动
      else if StringGrid1.Row < StringGrid1.RowCount-1 then
      begin
        StringGrid1.Row := StringGrid1.Row + 1;//行移动
        StringGrid1.Col :=1;
      end;
    end;