在stringgrid中如何实现按Enter键光标跳到下一网格?

解决方案 »

  1.   

    keydown事件
    if key = VK_ENTER then key = VK_TAP
      

  2.   

    keydown事件
    if key = VK_ENTER then key = VK_TAB
      
      

  3.   

    form1.KeyPreview :=true;
    procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if key= VK_RETURN then
      begin
        if StringGrid1.Selection.Right>=  StringGrid1.ColCount-1 then
           key:=VK_DOWN
        else
          key:=VK_RIGHT;
      end;
    end;
      

  4.   

    修改一下:
    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;
      

  5.   

    首先要保证:form1.KeyPreview :=true;
      

  6.   

    keydown事件
    if key = VK_ENTER then key = VK_TAB
      

  7.   

    是不是自动跳格?
    在stringGrid的OnKeyUp中增加如下代码:
     if StringG2.col < StringG2.colCount then
      StringG2.Col := StringG2.Col + 1;//列向移动
     if StringG2.Row < StringG2.RowCount then
      StringG2.Row := StringG2.Row + 1;//行移动
      

  8.   

    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;