在DBGridEh(Delphi7)里如何设置按TAB键自动跳到下一
列,当然,如果可以设置成回车能自动跳到下一列,而不
是跳出网格就更好了。

解决方案 »

  1.   

    覆盖DBGridEh的WinProc函数在新函数中假如对回车键的控制
      

  2.   

    写在DBGrid的OnKeyPress事件里:
    procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = #13 then
          DBGrid1.SelectedIndex := DBGrid1.SelectedIndex + 1;
    end;
      

  3.   

    jlee084(编程浪子) 的方法已经很好,楼主还要想什么方法呢?
      

  4.   

    回复人: jlee084(编程浪子)  兄弟的方法是跳到下一行,跳到下一列不用设置就可以
      

  5.   

    To taiguang(银狐) :
        不是啊,是跳到一列,那请问你怎么跳到下一列?楼主说的是按“回车”,不是“->”键。
      

  6.   

    明白,作个测试。
    可以这样:
    procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      If Key = #13 then
        If DBGrid1.SelectedIndex >= X Then 
          DBGrid1.SelectedIndex := 0
        Else 
          DBGrid1.SelectedIndex := DBGrid1.SelectedIndex + 1;
    end;
      

  7.   

    Postmessage(Object.handle,wm_keydown,vk_tab,0)
    object.handle:是你想讓TAB去的地方。
      

  8.   

    OptionsEh的ReturnAsTab=True就可以了,需要那么复杂吗?
      

  9.   

    OnKeyPress事件
      if Key = #13 then
      begin
        Key := #0;
        Perform (CM_DialogKey, VK_TAB, 0);
      end;
      

  10.   

    OptionsEh的ReturnAsTab=True不可以,我已经试过了,不知道为什么,不知道是不是Delphi7里是不是要打什么补丁?还是Ehlib3.0要打补丁?
      

  11.   

    RowSelected:=False;
    MultiSelected:=False;
    Tabs:=True;
    有属性可以用,干吗非要写代码?
      

  12.   

    看看这段程序,我试过了,运行得很好。
    procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);  begin
      if key=$0d then
      begin
       if dbgrid1.SelectedIndex+1=dbgrid1.Columns.Count then
       begin
       table1.Next ;
       dbgrid1.SelectedIndex:=0;
       end
       else
       dbgrid1.Selectedindex:=dbgrid1.SelectedIndex+1;
       end;
    end;