Tutorial 14 (Configuring a Business Object relationship)


Author
Message
StarkMike
StarkMike
Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)
Group: Forum Members
Posts: 436, Visits: 944
My sample is based on the pubs table, would it be easier for you to debug if I attached the project?
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Nah, don't worry about attaching the project. This is what I did:



1) Put the parent business object in DataGridView1 and the child in DataGridView2.

2) Handled the DataGridView1.Click event with this code:



Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click

If Me.DataGridView1.SelectedRows.Count = 1 Then

Me.BusinessObject11.Navigate(MicroFour.StrataFrame.Business.BusinessNavigationDirection.Absolute, Me.DataGridView1.SelectedRows(0).Index)

ElseIf Me.DataGridView1.SelectedCells.Count = 1 Then

Me.BusinessObject11.Navigate(MicroFour.StrataFrame.Business.BusinessNavigationDirection.Absolute, Me.DataGridView1.SelectedCells(0).RowIndex)

End If

End Sub



3) Set the ChildAutoFilterOption on the parent business object to MatchCurrentRow.

4) Made sure that the parent business object was set as the ParentBusinessObject on the child business object.



With those steps, when you click on the parent grid, it will filter the child records so that only the records within the child business object that match the currently selected parent will be visible.



Now, if you want to requery the database for child records each time you click on a parent record, you'll need to add an event handler for the Navigated event on the parent business object and repopulate the child business object with the appropriate records.
StarkMike
StarkMike
Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Ok, I feel a little confused and am not sure why i haven't got this to work. So I am going to reiterate what I have done to this point and we'll go from there.



I've created two business objects, a parent and a child. Both of these business objects are being filled through their ParentFormLoading events.



I've configured the ParentRelationship property on the child business object's class.



I've set the ParentBusinessObject property on the child business object.



I've set the ChildAutoFilter property on the parent business object to MatchCurrentRow.



Both of the business objects are filling properly with data, but I dont see any records in the child grid.



Have I forgot something? Unsure
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Make sure that both of your business objects' IsListSource properties are set to True.



After that, Mike, you haven't forgotten anything... what you can do is this:



Set a breakpoint in a button on the form so that we can check some of the values on the business objects at runtime in the Watch window.



Check the ChildBO.CurrentDataTable.Rows.Count property on the child business object and make sure it's greater than 0.



Check the ChildBO.Count property on the child business object and see if it's greater than 0. This value will tell you the number of visible records within the business object while the above value will tell you the number of records, visible or not.



Check the ChildBO.Filter property... it should be set to a value like this: "my_fk='parentpkvalue'" which hides all records within the child business object that don't match the current row within the parent business object. This value should follow the relationship you've defined on the business objects. If it doesn't then we have a problem Smile
StarkMike
StarkMike
Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)
Group: Forum Members
Posts: 436, Visits: 944
The ChildBO.CurrentDataTable.Rows.Count was equal to 18.



The ChildBO.Count was equal to 0.



The ChildBO.Filter was equal to 1=0.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
OK, well that explains that... 1=0 will hide all child records.



Whenever there are no records visible within the parent business object, the filter is set to that value so that it will hide the records within the child business object as well. This is kind of a bootstrap issue, because the child records are filtered whenever the ParentBusinessObject property is set on the child business object, and that happens during the form's InitializeComponent() method, and both business objects are empty.



Add this line of code in the parent business object's ParentFormLoading event handler, right after you fill it:



ParentBO.FilterChildRecords()



This will go through the filter logic again, and filter the records properly. After that, the records will be filtered automatically when the record within the parent business object is navigated.
StarkMike
StarkMike
Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Ok I added the code like you said and it did filter the chlid records for the first record in the parent business object. However it did not refresh the child filter upon navigation of the parent records.



The ChildBO.filter property returned this value: "pub_id=0736", the first row in the ParentBO.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Ah, yes, I assume you're using the .NET DataGridView, correct?



The business objects do not automatically attach to the events on the grids, and the grids do not notify the business objects to navigate, since the grid views the business object as a big, flat list. So, within the RowClicked and/or CellClicked events of the grid, you will need to call:



ParentBO.Navigate(BusinessNavigationDirection.Absolute, e.RowIndex)



This will tell the business object to navigate to the desired record, thereby synching with the child business object.
StarkMike
StarkMike
Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Thanks, works now. A couple related questions. When I move to a record in the parent grid that doesnt have related child records it doesnt clear the grid, it just leaves the records from the previous record.



Plus when I tried to add a child record I got an error. I have attached a screen shot of that error. Keep in mind that I am using the pubs database and my parent is Publishers and my child is Titles. I think it has something to do with the primary key in Titles being Alphanumeric. Not sure how to resolve the problem though.



Thanks
Attachments
New Child Record Error.jpg (144 views, 85.00 KB)
StarkMike
StarkMike
Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)
Group: Forum Members
Posts: 436, Visits: 944
And another question.... If I wanted to put an Orders grid at the bottom of the CustomerMaintenance form found in the Tutorials what event from the Maintenance form would I use to put my ParentBO.Navigate code in? So that the orders would refresh each time i went to a different customer.



Thanks
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