在StringGrid中焦点当前在一个单元格上,如何实现回车键换到另一个单元格上?

解决方案 »

  1.   

    发送一个键盘的按键消息给 StringGrid 。
      

  2.   

    在dbgrid1keypree事件中写:
    if(key=#13)then
    keybd_event(vk_tab,0,0,0);
      

  3.   

    procedure TInputForm.strgCostKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if (key=13) and (strgCost.Row<strgCost.RowCount-1) then
        if strgCost.Col=strgCost.Cols then begin
          strgCost.Row:=strgCost.Row+1;
          strgCost.Col:=1;
        end
        else
          strgCost.Col:=strgCost.Col+1;
    end;
      

  4.   

    对不起搞错了,应该是:
    procedure TInputForm.strgCostKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if (key=13) and (strgCost.Row<strgCost.RowCount-1) then
        if strgCost.Col=strgCost.ColCount-1 then begin
          strgCost.Row:=strgCost.Row+1;
          strgCost.Col:=1;
        end
        else
          strgCost.Col:=strgCost.Col+1;
    end;
      

  5.   

    if key=chr(vk_return) then
      if dbgrid1.selectedIndex=dbgrid1.Columns.Count-1 then
         dbgrid1.selectedIndex=0
      else
         dbgrid1.selectedIndex=dbgird1.selectedIndex+1;
      

  6.   

    刚才没经过测试,最终版本,呵呵
    procedure TForm1.strgCostKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if (key=13) then
        if (strgCost.Row=strgCost.RowCount-1) and (strgCost.Col=strgCost.ColCount-1) then
          Exit;
        if (strgCost.Col=strgCost.ColCount-1) then begin
          strgCost.Row:=strgCost.Row+1;
          strgCost.Col:=1;
        end
        else
          strgCost.Col:=strgCost.Col+1;
    end;