Parent-Child in Grids


Author
Message
Sarosh
Sarosh
StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)
Group: Forum Members
Posts: 22, Visits: 116
Hi!

Have a form with

Two BO's (projectBO, subProjectBO)

Two  BusinessBindingSource's (projectBBS, subProjectBBS)

Two grids (projectDGV, subProjectDGV)

Have setup the ParentChild relationship as mentioned in the help but when I change rows in the parent grid (projectDGV) nothing seems to happen in the child grid (subProjectDGV) The Child grid always shows all rows. Have set the ChildAutoFilterOption to MatchCurrentRow on the Child BO

I call the FillAll() for both BO's in the Form's Constructor (after the InitializeComponent())

this.projectBO.FillAll();

this.subProjectBO.FillAll();

Have three questions:

1] What am I doing wrong?

2] Are all rows from the child table being retrieved and then filtered based on the Parent's key or only rows matching the Parent's Key being retrieved from the server?

3] How can I use SP's to retrieve data for the Parent and Child?

Thanks

Sarosh

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I can help with 3] retrieving data using sprocs (assuming that's what SPs means!)



In a fill method using code something like this:



Public Sub FillBySproc(ByVal paramValue As Integer)

Using cmd As New SqlCommand()

cmd.CommandType = Data.CommandType.StoredProcedure

cmd.CommandText = "sp_YourSproc"



'-- Setup parameters (add for any parameters needed by the sproc)

cmd.Parameters.Add("param1",Data.SqlDbType.Int)

cmd.Parameters("@param1").Value = paramValue ' Passed in value



'-- Load the data table

Me.FillDataTable(cmd)

End Using

End Sub




The sproc should return the records to fill the BO. The field order doesn't matter, but the name of the columns does - it should match the field names mapped to the BO.
Sarosh
Sarosh
StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)
Group: Forum Members
Posts: 22, Visits: 116
Hi!

Yes, by SP I meant Stored Procedure.

Thanks for the code that was exactly what I was looking for, just one more thing, what should the code look like for a child BO so that it retrieves only rows for the current Parent's Key rather than retrieving all rows and then they get filtered on the client side.

In other words how can I get the Parent's key from within the child BO so that I could then pass that to the SP which in turn would only retrieve the rows that matched the Parent's Key.

Thanks

Sarosh

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Well, typically, I'd figure out what's going on in the parent BO's navigated event. This is fired after the parent navigates to a new row. At that point you could then call the fill method that fills the child. I.e.



Private Sub parentBO_Navigated(ByVal sender As Object _

, e As Microfour.StrataFrame.Business.NavigatedEventArgs) Handles parentBO.Navigated

'-- Validate that there is a current row.

If Me.parentBO.CurrentRowIndex < 0 Then Return



'-- Get the parent ID

' where PKField is the name of the PK field of the parent...

Dim id As Integer = Me.parentBO.PKField



'-- Load the child: two options

' First, if there is a parent child relationship set for these BOs...

Me.childBO.FillByParentPrimaryKey(id)



' Second, use your sproc fill method

Me.childBO.FillBySproc(id)

End Sub




Obviously, you'd pick one method to fill the child BO. This method would not use the filtering of the child when a new parent is navigated to (the whole point of that would be to avoid all this code). Hope this helps!
Sarosh
Sarosh
StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)StrataFrame Beginner (22 reputation)
Group: Forum Members
Posts: 22, Visits: 116
Hi!

Yes this helped a lot!

One thing I am still not clear about is if I have related the Parent-Child BO's and I don't write any other code then is the filtering happening on the client side? i.e. the Child's FillAll() is internally called which brings all rows from the child table and then those rows are filtered.

Sarosh

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
The child BO is not automatically populated, just filtered when using the auto filter settings.  You still need to manually populate the child BOs records.  There is actually not an intrinsic method called FillAll(), but rather FillByParentPrimaryKey and FillByParent which will both load the child records when you have the relationship setup.
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