接上面,DBGrid里的内容全部重新排序,如果数据量大一点,根本不知道我刚才修改的那条数据保存在哪里.如果新增某一条数据后,也是这样子.
怎样才能使我修改或是新增后,DBGrid所定位的记录还是我修改或是新增的那条记录??

解决方案 »

  1.   

    用你adoquery的locate方法定位就可以了。
      

  2.   

    procedure TFSearch.DBGrid1CellClick(Column: TColumn);
    var
      point:integer;
    begin
      point := DBGrid1.DataSource.DataSet.fieldbyname('id').AsInteger;
      ADOQuery1.Close;
      ADOQuery1.SQL.Clear;
      ADOQuery1.SQL.Add('select * from personnel_change where PersonId = ' + inttostr(PersonId));
      ADOQuery1.Open;
      ADOQuery1.Active := True;
    end;
    上面是一个主从表的查寻的,你可以稍改一下就可以实现你的功能了。
      

  3.   

    用adoquery.last,应该新增的是最后一条
      

  4.   

    同意楼上的~
    不过也可以用其它方法查询!
    比如直接写查询SQL执行就OK了.
    还有一种办法就是BookMark吧(书签)
      

  5.   

    用dbedit dbcombobox就可以容易解决显示的问题。对于dbgrid行的定位,你加下面的代码可以把选中的行的颜色改变。
    ---------
    procedure TFormNewOrder.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin    if ((State = [gdselected]) or (State = [gdselected,gdfocused])) then
          begin
            DBGrid1.Canvas.Brush.Color:=clOlive;
            
          end;    DBGrid1.Canvas.Pen.Mode:=pmMask;
        DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
    end;
      

  6.   

    在post之前,先存下当前的位置,然后afteropen后再用locate定位到指定的位置.
      

  7.   

    to : hugoon(ギギ孤独code客ギギ) 
    ......
      ADOQuery1.Open;
      ADOQuery1.Active := True;  //这一行是干嘛用的?
      

  8.   

    谢谢各位:
    我用locate搞定了.