StrataFrame Forum

Why does Childformdialog not work correctly

http://forum.strataframe.net/Topic32867.aspx

By Thomas Holste - 1/29/2015

Hi there,

I have a main form with a BO and a Businessbindingsource to use it with a datagridview. To add new records I call a childform with the childformdialog. This is how it's done:



LieferBO1.Add()

Dim para As New Liefneuparams

para.cNeu = "N"

para.cModule = "Latitelneu"

para.cLiefer = ""

para.lSolo = False

If Childliefneu.ShowDialog(para) = DialogResult.OK Then .......



This works the first time I call it but the second time the liefpos.add()  does not add a new record and the bo is positioned on the actual record.

Does anyone know why this is not working?

Best regards

Thomas











By Trent L. Taylor - 1/29/2015

Remember that the BOs are essentially just being passed over.  When I am working on child dialogs, I definitely use the child form dialog so I can map my BOs, but I manage the state of the as part of the showing of the child form dialog.  First, take advantage of the SaveCurrentDataTableToSnapshot method on the BO.  This is better than an undo because you may go into the child form more than once as part of editing that record.  The first time, things would be good, but if you go back in and cancel...well, you just toasted the record or table state.  For example:

private void AddRecord() 
{      
      myBo.SaveCurrentDataTableToSnapshot("Adding");      
      myBo.Add();      

      if(myChildForm.ShowDialog() == DialogResult.Cancel)       
      {
            myBo.RestoreCurrentDataTableSnapshot("Adding", true);
      }
}


Take this same logic and apply it to an edit.  You would just replace the Add with an Edit.  You can do it in the same method if you pass over the state you are expecting and the record you are wanting to load.  Prior to the edit, you can do a seek to the PK or whatever if you pass it in.
By Thomas Holste - 1/30/2015

Hi Trent,




thank you for the Explanation but the error was much simpler. After adding the record I performed a sort on the BO to have the new record shown in the right Position. Resetting the sort before adding works fine.

Best regards

Thomas
By Trent L. Taylor - 1/31/2015

Glad you got it going!