請問大家,我的想法是,在插入數據時,不允許用戶移動到其他記錄。應該如何做?
我試過,用OnBeforeScroll事件,但不行,在這事件裡檢查的狀態不是dsInsert。所以沒辦法終止移動,請問大家有辦法嗎?
我是使用ADOQuery+cxGrid的

解决方案 »

  1.   


    想实现你这样的功能,要设置一个全局ds_insert状态标志。
    如:
    在插入时,设置ds_insert:=True;
    在OnBeforePost事件中,检查其状态,如果为真,则Abort;如果真的要保存,先设置ds_insert:=False,再Post.
      

  2.   

    wywry(Wyatt),試著在用你的方法,但Abort後出錯。錯誤信息如下
    EListError:List index out of bounds(0)
      

  3.   

    procedure TForm1.ADOQuery1BeforeScroll(DataSet: TDataSet);
    begin
      if DataSet.State = dsInsert then
        Abort;
    end;这样应该可以
      

  4.   

    cxp82428(出现派),試過不行的。BeforeScroll前,會自動Post,所以狀態不會是dsInsert。
      

  5.   

    BeforeScroll前会Post?我用自带得DBGrid就可以
      

  6.   

    suiyunonghen,如何鎖?什麼時候鎖?