Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread How / When to refresh a dataset/grid
Wed, Sep 23 2015 4:13 AMPermanent Link

Petter Topp

From a "UserAdmin" form with a grid (bound to a dataset) I open a new form (Modal) in which user data can be entered.
Data is stored in my database using a method on the server.
When the "NewUser" form is closed I return to my "UserAdmin" form, where I would like to automatically update my grid/dataset to reflect the changes (new record).

What would the best approach for this be?

Br
Petter
Wed, Sep 23 2015 8:40 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Petter,

<< What would the best approach for this be? >>

The easiest way is to simply re-load the rows for the dataset using Database.LoadRows.  If you want to save the current dataset position, just save the RowNo property, and then restore it afterward.

http://www.elevatesoft.com/manual?action=viewprop&id=ewb2&comp=TDataSet&prop=RowNo

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Sep 24 2015 12:37 AMPermanent Link

Petter Topp

Hi Tim.

I have been unclear - what I'm looking for is an event that tells me that the last form was closed / insert was successful.

Br
Petter
Thu, Sep 24 2015 4:54 AMPermanent Link

Walter Matte

Tactical Business Corporation

Petter:


What I do is have a procedure in the calling form - example "DoSelectedSearch"  - I pass this procedure to the form being called.  The called form then executes the procedure before "close/ insert".  

The is similar to the MessageDlg  where you pass the procedure to be called.

Walter


//  TfrmOrganization

 public
     { Public declarations }
     procedure DoSelectedSearch(Sender: TObject);
  end;

procedure TfrmOrganization.DoSelectedSearch(Sender: TObject);
begin
 Org.Close;
 Org.Params.Clear;
 Org.Params.Add('iOrgId='+ Inttostr(frmOrgSearch.OrgId));
 Database.LoadRows(org,false);
end;

// Clicj Search to see search Form
procedure TfrmOrganization.btnSearchClick(Sender: TObject);
begin
 frmOrgSearch.SelectedSearch := DoSelectedSearch;
 frmOrgSearch.ShowModal;
end;

//------  The Search Form ------

// TfrmOrgSearch

  private
     { Private declarations }
    FSelectedSearch : TNotifyEvent;

  public
     { Public declarations }
    OrgId : integer;
    property SelectedSearch : TNotifyEvent read FSelectedSearch write FSelectedSearch;

  end;

// Click Select Button to choose the record
procedure TfrmOrgSearch.btnSelectClick(Sender: TObject);
begin
 // Find is the dataset that displays the list of records to choose from
 if Find.RowCount = 0 then
   exit;

 OrgId := Find.Columns['OrgId'].AsInteger;
 Find.Close;
 
 if Assigned(FSelectedSearch) then
   FSelectedSearch(nil);

 Close;
end;
Thu, Sep 24 2015 5:28 AMPermanent Link

Petter Topp

Perfect Walter, I'm still learning.

Thank you very much.
Petter
Image