Childformdialog-problem


Author
Message
Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi there,

I have set up a childformdialog and want to have all the Add/EDIT-logic within the

childform. I call the childform with a param-object this way:



Dim aParam(1) As Object

aParam(0) = "N"    --->New record to add, the edit-button on the parentform would set an "E"

aParam(1) = "LIEFMAIN"    --> Name of the calling form

Childliefneu.ShowDialog(aParam)



In the childform I use the following code



Public Sub New(ByVal ParamArray aParam() As Object)

MyBase.new()

' Dieser Aufruf ist für den Designer erforderlich.

InitializeComponent()

' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

If aParam(0) = "N" Then

Me.lNeu = True

Me.Text = "Lieferanten aufnehmen"   -->"Add a supplier"

LieferBO1.Add()

Else

Me.lNeu = False

Me.Text = "Lieferanten bearbeiten"   --> "Edit a supplier"

LieferBO1.Edit()

End If

Me.cModule = aParam(1)

LieferBO1.Refresh()

Me.Refresh()

End Sub



When I call the childform to add a record, the form does not show an empty record which I expected to be added but the record the current row index points to and the controls are all disabled.

Is my approach wrong or did I miss something?

Thanks in advance

Thomas
StrataFrame Team
S
StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Sorry, Thomas, I just saw this one.

The way the ChildFormDialog works is that it first creates a copy of your form with the Activator class using the parameters you supply (so it calls your constructor), then it replaces the references of the business objects on the forms with the translated references.  So, whatever you do to the business objects within the constructor, you're doing to the wrong business object reference.  You're adding/editing the business object, and then it is replaced with the correct business object, so it looks like nothing is happening, because you're calling those methods on the wrong BO reference.

What you need to do is save off the first parameter (the "N" or whatever else you pass) in a private field on the child form.  Then override the OnLoad() method of the form and do your Add/Edit logic there because the business object will have been translated.
Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Ben,

thanks a lot for your explanation. That shoqs me clearly why some of my approaches

went wrong. I Will try this immediately.

Best regards

Thomas
Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Ben,

I tried it and shifted the add edit code into an Overwritten onload-method



Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

MyBase.OnLoad(e)

If Me.lNeu Then

LieferBO1.Add()

Else

LieferBO1.Edit()

End If

LieferBO1.Refresh()

Me.Refresh()

End Sub



Now the follwing happens: If I start the form with a parameter for editing, the correct record is shown for editing. I can change values and save them, everything is fine.

When I choose to add a record. the form does not show, as I expected it, empty fiellds (controls like textboxes) for adding but behaves like I had choosen to add the actual record my grid is showing on the calling form.

Checking this with the debugger shows me, for example, that I enter the form with 79 records, the add-method of the BO is callled, after this I have 80 records, but the controls (text- and checkboxes and combos) aren't refreshed. 

What might I have done wrong?

Best regards

Thomas
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search