在dbgrid中,我添加一个计算字段,然后在计算事件中,对该计算字段赋值。
我这里是将RecordNo赋给该字段,但是奇怪的问题出现了在第一行竟然显示出来的是-1,接下来时2、3...,但是如果我对某行数据修改,post后第一行的RecordNo将变成1,怪不而且我用
Adotable1.first;
showmessage((inttostr(adotable1.recordno));
显示的也是1

解决方案 »

  1.   

    呵呵...我也遇到过此情况...我的解决方法是在在事件AfterScroll里添加if inttostr(adotable1.recordno)<0 then
       NumberLabel1.Caption:='1';
      

  2.   

    procedure TForm1.ADOTable1CalcFields(DataSet: TDataSet);
    begin
    //ADOTable1.First;
    //ADOTable1.FieldByName('recordno').AsString :=inttostr(StrtoInt(ADOTable1.FieldByName('bianhao').asstring)+StrToInt(ADOTable1.FieldByName('jiner').AsString));
    ADOTable1.FieldByName('recordno').AsString := inttostr(ADOTable1.Recno);
    if adotable1.RecNo<0 then
       ADOTable1.FieldByName('recordno').AsString:='1';
    end;
    这样就可以了!
      

  3.   

    procedure TForm1.ADOTable1CalcFields(DataSet: TDataSet);
    begin
    ADOTable1.FieldByName('recordno').AsString := inttostr(ADOTable1.Recno);
    if adotable1.RecNo<0 then
       ADOTable1.FieldByName('recordno').AsString:='1';
    end;
    不好意思发错了!