我想在TDBGrid控件中编辑某一条记录字段的时候,按回车或Tab键移到本记录
的下一个字段上进行编辑,当到达最后一个字段的时候,再按回车或Tab键进入
下一条记录的首字段。
另外,如何在这个TDBGrid的一个字段中加入一个再编辑控件,比如说TComboBox或TUpdown,这样用户可以选取一个值。

解决方案 »

  1.   

    :::回车替Tab下移控件::: 
    需要用回车键代替TAB键下移一个控件时,把KeyPress设为True,加入下列代码拦截击键:
    Procedure TForm1.FormKeyPress(Sender:Tobject;Var Key:Char);
    Begin
     if key=#13 then { 判断是按执行键}
     if not (ActiveControl is TDbgrid) Then
     Begin { 不是在TDbgrid控件内}
      key:=#0;
      perform(WM_NEXTDLGCTL,0,0);{移动到下一个控件}
     end else
     if (ActiveControl is TDbgrid) Then{是在 TDbgrid 控件内}
     begin
      With TDbgrid(ActiveControl) Do
      if Selectedindex<(FieldCount-1) then
      Selectedindex:=Selectedindex+1{ 移动到下一字段}
      else Selectedindex:=0;
     end;
    End;  
      

  2.   


      dbgrid的onkeydown中
      
      if key=13 then
        key:=vk_tab;
     第二个问题,在drawdatacell事件中  if (gdFocused in State) then  //判断是否得到焦点
      begin
         if (Field.FieldName = '要显示combobox的列的字段名' ) then
         begin
             ComboBox1.Left := Rect.Left + DBGrid1.Left;
             ComboBox1.Top := Rect.Top + DBGrid1.top;
             ComboBox1.Width := Rect.Right - Rect.Left;
             ComboBox1.Height := Rect.Bottom - Rect.Top;
             ComboBox1.Visible := True;
         end;
      end;
      

  3.   

    显示combobox控件的部分基本是正确的,但在调节每个cell单元的时候,
    combobox就不能正确显示了,请问在那个事件里处理这种情况
      

  4.   

    好麻烦呵
    用DevExpress Grid吧多快好省
      

  5.   

    to wave(小浪花)这一段
      if Selectedindex<(FieldCount-1) then
      Selectedindex:=Selectedindex+1{ 移动到下一字段}
      else Selectedindex:=0;
     应写成
    if Selectedindex<(FieldCount-1) then
      Selectedindex:=Selectedindex+1{ 移动到下一字段}
      else 
          begin
         adoquer1.next;//必需下一移一条
        Selectedindex:=0;
       end;
      

  6.   

    我按tanlijun37(tlj)说的试了一次,但奇怪的是,当跳到下一条记录时,
    获得焦点的竟然是第二个字段,我也不知道为什么是这样,有谁知道,
    不吝赐教
      

  7.   

    selectedIndex:= selectedIndex +1 造成的。0 + 1 = 1 了tanlijun37 的程序应该没有问题吧。