By Ger Cannoll - 6/8/2008
I'm trying to set up a Child Form.I 've set up the Parent and Child Business Objects. I've dropped both on a SF Maintenece form. I've set up a PageFrame , one of the tabs is the Child Form. I have dropped a BusinessBindingSource on the form and set its datasource as the child bus object. I have also set the ParentBusinessObject of the childbuiness object on the form.I am displaying all fields in the child.As I naviagte through the patrent, I would expect to see the childdren in the grid, as the parent is navigated to...but nothing is appearing in the child grid. Should this behaviour be automatic, or is there someting I need to do to 'GET'the children into the grid ?
|
By Guillermo Vilas - 6/8/2008
Hello Gerard
It is always useful going through the SF samples provided, the way it works for me is adding this to the navigated event of the primary BO
Private Sub Orders_Navigated(ByVal e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles Orders.Navigated
If Orders.Count > 0 Then
Me.OrderItems.FillByParentPrimaryKey(Me.Orders.pk)
End If
End Sub
I hope this helps
|
By Ger Cannoll - 6/8/2008
Hi Guillermo.I have inserted code: ChildBO.FillByPrimaryKey(ParentBO.PrimaryKeyField); in the Navigating event of the Parent BO but still nothing happenning on the child grid. My Parent Primary Key is not the key into the child..another field on the Parent Table acts as the key....dont know if this matters ?
|
By Edhy Rijo - 6/9/2008
Gerard O Carroll (06/09/2008)
My Parent Primary Key is not the key into the child..another fieldon the Parent Table acts as the key....dont knowif this matters ?
Hi Gerard,
Yes it does matter, since the FillByPrimaryKey will identify the defined PrimaryKey field(s) in the parent. I believe you will have to create your own FillBy method in the child BO and use that instead.
|
By Trent L. Taylor - 6/9/2008
Edhy is correct. You will just need to create your own Fill method to load the records that you need based on the specified parent record. So just create a Fill method on the child BO and call that Fill method on the Navigated event.
|
By Ger Cannoll - 6/9/2008
Some sample code would be appreciated as I am unclear as to what a '"Fill" method is or what code to put in it To recap, My Parent Business Object has a Pk feld(Primary Key) as well as a ParentStkref Field which links to the Child Table (The linked field in the Child table is say ChildStkref)
|
By Trent L. Taylor - 6/9/2008
Below would be an example of a Fill methodPublic Sub FillMyBO(ByVal ParentValue As Integer) '-- Establish Locals Dim cmd As New SqlCommand("SELECT * FROM MyTable WHERE myParentField = @parentFieldValue") '-- Create the parms cmd.Parameters.AddWithValue("@parentFieldValue", ParentValue).SqlDbType = SqlDbType.Int '-- Fill the BO Me.FillDataTable(cmd) End Sub
|
By Edhy Rijo - 6/9/2008
Trent L. Taylor (06/09/2008) Edhy is correct. You will just need to create your own Fill method to load the records that you need based on the specified parent record. So just create a Fill method on the child BO and call that Fill method on the Navigated event.
Hi Gerard,
Here is a code I use in a child BO:
Public Sub FillByPolicy(ByVal FK_Policy As Integer)
Using cmd As New SqlCommand()
cmd.CommandText = String.Format("SELECT * FROM {0} WHERE FK_Policy={1} ", Me.TableName, FK_Policy)
Me.FillDataTable(cmd)
End Using
End Sub
After creating this method, compile your BO library or your solution then use that method instead of the FillByParentPrimaryKey().
|
By Ger Cannoll - 6/9/2008
I have set up a Separate Fill method but am getting an error. In trying to find out the reason for the error, I have put a Messagebox in the Navigating event of the parent business object as MessageBox.Show(ParentBO.Stref) . I get a --> Current Row could not be evaluated because the current row index is out of range..record count is the last record in the business object...the error is coming from the Get for this field ..loValue=This.CurrentRow["stref"] in the framewrok code. If I take out the MessageBox, I can scroll up and down the parent business object without any errors.My Messagebox is just trying to display a field on the table ....but it seems to be going to EOF for some rason... I dont have any orhte code in there except this.
|
By Edhy Rijo - 6/9/2008
Hi Gerard,At this point it is better if you post the exact message you are having along with the complete code so we can take a look and see where you may be missing the point. Also for testing instead of Navigating event use the Navigated and make sure your use the ParentBO.Count>0 as pointed by Guillermo.
|
By Trent L. Taylor - 6/10/2008
When you get an error, posting the stack trace is very helpful. But in this case, it sounds like you are trying to query in one of two circumstances:- You have code somewhere in a constructor of a class (New) or a Load event and it is getting executed at design-time
- Or more likely, you are relying on the parent BO to populate the child. However, there are no records in the parent record, so you get an index out of range exception. Test on the Count property of the BO before calling the Requery of the child so that the error will not occur.
|