if key=vk_return then
    begin
      with dgPriceGoods do
        begin
          if SelectedIndex < FieldCount - 1 then //不是最后一列,移向下一列
            begin
              SelectedIndex:=SelectedIndex+1;
            end
          else if SelectedIndex = FieldCount - 1  then //最后一列
            begin
              if (DataSource.DataSet.RecNo<>DataSource.DataSet.RecordCount) then //不是最后一行
                begin
                  DataSource.DataSet.Next;
                  SelectedIndex:=0;
                end
              else if (DataSource.DataSet.RecNo=DataSource.DataSet.RecordCount) or
                      (DataSource.DataSet.RecNo=-1) then //最后一行或新增加的行
                begin
                  DataSource.DataSet.Append;
                  //key:=vk_down;
                  SelectedIndex:=0;
                end;
            end;
        end;
    end;

解决方案 »

  1.   

    过了n天,还是自己解决了!
    代码如下:
      if key=vk_return then
        begin
          with dgPriceGoods do
            begin
              if SelectedIndex < FieldCount - 1 then //不是最后一列,移向下一列
                begin
                  SelectedIndex:=SelectedIndex+1;
                end
              else if SelectedIndex = FieldCount - 1  then //最后一列
                begin
                 if (DataSource.DataSet.RecNo=DataSource.DataSet.RecordCount) or
                          (DataSource.DataSet.RecNo=-1) then //最后一行或新增加的行
                    begin
                      DataSource.DataSet.Append;
                      //key:=vk_down;
                      SelectedIndex:=0;
                    end
                else  //不是最后一行
                  begin
                    DataSource.DataSet.Next;
                    SelectedIndex:=0;
                  end
                end;
            end;