请问如何判断Tsb键的光标停在DBGRID内的某一字段?我是想禁用TAB键新增行,只要Tab跳到最后一个字段要新增时,我就要
取消新增!

解决方案 »

  1.   


    procedure TForm1.DBGrid1ColExit(Sender: TObject);
    begin
      if DBGrid1.SelectedField.FieldName = 'ff' then
        ADOQuery1.Cancel;
    end;
      

  2.   

    procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      s:string;
      i,j,m,n:Integer;
    begin
      i:=self.DBGrid1.Columns.Grid.SelectedIndex;
      j:=self.DBGrid1.Columns.Grid.FieldCount;
      m:=self.DBGrid1.DataSource.DataSet.RecNo;
      n:=self.DBGrid1.DataSource.DataSet.RecordCount;
      if Key=9 then
      begin
        if (m<n) or ((n=m) and (i+1<j)) then
        begin
          if i+1<j then
            self.Label1.Caption:=self.DBGrid1.Columns.Grid.Fields[i+1].FieldName
          else
            self.Label1.Caption:=self.DBGrid1.Columns.Grid.Fields[0].FieldName;
        end
        else
          key:=0;
      end;
    end;