in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

refresh after AppendRecord

Last post 10/9/2007 6:27 AM by liu ding. 11 replies.
Page 1 of 1 (12 items)
Sort Posts:
Previous Next
  • 9/15/2007 7:24 AM

    refresh after AppendRecord

    hi, all. i've a problem under Delphi 7 and cxgrid. When i append record,cxgrid can't refresh at once,also the new record cann't append to cxgrid .

    here is my code(i have a DB table: log):

    procedure TForm1.Button1Click(Sender: TObject);
    var
        Column:   TcxGridColumn; 
    begin
        with adoquery1 do
         begin
            sql.Clear;
            sql.Text := 'insert into log (logtitle,logtag) values ("dfs","dfs")';
            ExecSQL;
         end;
          Column:= cxGrid1DBTableView1.CreateColumn;
          Column.Caption:='dfs';
          cxGrid1DBTableView1.DataController.AppendRecord;
          cxGrid1DBTableView1.DataController.Values[0,1]:='dfs';
          cxGrid1DBTableView1.DataController.Values[0,2]:='dfs';
          cxGrid1DBTableView1.DataController.Post;
    end;

    can anybody help me? Thanks a lot .

     

    Filed under: ,
  • 10/2/2007 5:33 AM In reply to

    Re: refresh after AppendRecord

    liu ding:
          cxGrid1DBTableView1.DataController.AppendRecord;
          cxGrid1DBTableView1.DataController.Values[0,1]:='dfs';
          cxGrid1DBTableView1.DataController.Values[0,2]:='dfs';
          cxGrid1DBTableView1.DataController.Post;

    Can you try to modify this as follows:

    uses
      cxDataUtils;

    cxGrid1DBTableView1.DataController.Append;
    cxGrid1DBTableView1.DataController.SetEditValue(1, 'dfs', evsValue);
    cxGrid1DBTableView1.DataController.SetEditValue(2, 'dfs', evsValue);
    cxGrid1DBTableView1.DataController.Post;

  • 10/3/2007 11:56 AM In reply to

    Re: refresh after AppendRecord

    FWIW:  I always prefer to work directly with the dataset (the primary datasource), rather then the grid (a secondary datasource).


     

    Ed Dressel
    DX Squad
  • 10/5/2007 10:18 PM In reply to

    Re: refresh after AppendRecord

    thx ,bert,it works!!!  :)

    but i have a new problem,when i add record again,it warns me :can not update,current lock. do you know why? thanks

    Filed under:
  • 10/5/2007 11:18 PM In reply to

    Re: refresh after AppendRecord

    Bert Binnenmarsch:

    Can you try to modify this as follows:

    uses
      cxDataUtils;

    cxGrid1DBTableView1.DataController.Append;
    cxGrid1DBTableView1.DataController.SetEditValue(1, 'dfs', evsValue);
    cxGrid1DBTableView1.DataController.SetEditValue(2, 'dfs', evsValue);
    cxGrid1DBTableView1.DataController.Post;

    i use MS Access,my db has an "id" field which is a Automatic Number。 when i append a new record the cxgrid displays wrong number.

    eg: previous record's id is 1 (n) , after i append a record,the record's id value is 3 (n+2). ???

       

  • 10/8/2007 7:46 AM In reply to

    Re: refresh after AppendRecord

     

    liu ding:

    but i have a new problem,when i add record again,it warns me :can not update,current lock. do you know why?

    liu ding:

    i use MS Access,my db has an "id" field which is a Automatic Number。 when i append a new record the cxgrid displays wrong number.

    eg: previous record's id is 1 (n) , after i append a record,the record's id value is 3 (n+2). ???

    The message 'can not update,current lock' is probably caused by Access. I have no idea how to get rid of it.

    After inserting a new record with an autoinc field, the database engine (Access in this case) should assign it the next available value. In similar situations my experience is that the grid shows the correct autoinc value. My database engine is NexusDB, so it is possible that Access is doing something wrong.

    My suggestion is to give it a try with a different database engine and see if it solves your problem. I can recommend NexusDB (www.nexusdb.com).

    Filed under:
  • 10/8/2007 11:40 PM In reply to

    Re: refresh after AppendRecord

    Bert, thanks a lot.
    But i've never used NexusDB ,and my all DBs use MS Access,So i have to find a way to solve the problem; Really thanks for you help! :)

  • 10/8/2007 11:48 PM In reply to

    Re: refresh after AppendRecord

     Try using an in-memory dataset, such as TdxMemData. It does sound like it is specific to Access.

    Ed Dressel
    DX Squad
  • 10/9/2007 4:35 AM In reply to

    Re: refresh after AppendRecord

    Bert, Ed Dressel,  i've found the reason.

    That is:

       When i use cxgrid's method "AppendRecord" ,  it doesn't operate the DB and insert record.  But "Append" does.  As a matter of fact , i insert record twice.

     

    Do you know how to delete a record which i select in cxgrid? update rapidly?

    my code is ( it doesn't  update rapidly ) :

    //************************** delete record  ***********************************// 

    procedure TForm4.dellog(id: Integer);
    begin
    If Application.MessageBox('Delete?','',MB_OKCANCEL+MB_ICONQUESTION+MB_DEFBUTTON1+MB_APPLMODAL)=ID_OK Then
      if id > 0 then
        begin
          with adoquery2 do
           begin
           close;
           sql.Clear;
           ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;Persist Security Info=False';
           sql.Add('delete * from log where id =' + inttostr(id));
           ExecSQL;
           end;
        end;
    end;

    //**************************** End  **********************************//

     

     

     

  • 10/9/2007 4:42 AM In reply to

    Re: refresh after AppendRecord

    With every delete the grid will get a notification and update itself, to avoid that use the following:

    xGrid1DBTableView1.BeginUpdate;
      for j := 0 to High(intarr) do
            begin
            dellog(intarr[j]);
            end;
    xGrid1DBTableView1.EndUpdate;

    It is also possible to use xGrid1DBTableView1.DataController.EndUpdate, but I don't know the exact difference.

  • 10/9/2007 6:13 AM In reply to

    Re: refresh after AppendRecord

    Bert Binnenmarsch:

    With every delete the grid will get a notification and update itself, to avoid that use the following:

    xGrid1DBTableView1.BeginUpdate;
      for j := 0 to High(intarr) do
            begin
            dellog(intarr[j]);
            end;
    xGrid1DBTableView1.EndUpdate;

    It is also possible to use xGrid1DBTableView1.DataController.EndUpdate, but I don't know the exact difference.

     Bert , i did as you said, but it seemed no effect.

    also ,i tried DataController.EndUpdate .. - -!

     

  • 10/9/2007 6:27 AM In reply to

    Re: refresh after AppendRecord

    hoho, i 've got it.

    use this :

    //*********** it can delete which you select(include single and multiline *************// 

    cxGrid1DBTableView1.DataController.DeleteSelection;

    //************************// 

     and set cxGrid1DBTableView1 mutilSelect true;

    Now ,how can I update data when i modify a record?

Page 1 of 1 (12 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED