﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Parent-Child in Grids</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Fri, 25 Sep 2026 06:00:12 GMT</lastBuildDate><ttl>20</ttl><item><title>Parent-Child in Grids</title><link>http://forum.strataframe.net/FindPost9432.aspx</link><description>Hi!&lt;P&gt;Have a form with&lt;/P&gt;&lt;P&gt;Two BO's (projectBO, subProjectBO)&lt;/P&gt;&lt;P&gt;Two &amp;nbsp;BusinessBindingSource's (projectBBS, subProjectBBS) &lt;/P&gt;&lt;P&gt;Two grids (projectDGV, subProjectDGV)&lt;/P&gt;&lt;P&gt;Have setup the ParentChild relationship as mentioned in&amp;nbsp;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 &lt;SPAN style="FONT-WEIGHT: bold; COLOR: #4169e1"&gt;MatchCurrentRow&lt;/SPAN&gt; on the Child BO&lt;/P&gt;&lt;P&gt;I call the FillAll() for both BO's in the Form's Constructor (after the &lt;FONT size=2&gt;InitializeComponent())&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.projectBO.FillAll()&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.subProjectBO.FillAll();&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;Have three questions:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;1] What am I doing wrong?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;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?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;3] How can I use SP's to retrieve data for the Parent and Child?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sarosh</description><pubDate>Fri, 08 Jun 2007 22:42:49 GMT</pubDate><dc:creator>Sarosh</dc:creator></item><item><title>RE: Parent-Child in Grids</title><link>http://forum.strataframe.net/FindPost9456.aspx</link><description>The child BO is not automatically populated, just filtered when using the auto filter settings.&amp;nbsp; You still need to manually populate the child BOs records.&amp;nbsp; 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.</description><pubDate>Fri, 08 Jun 2007 22:42:49 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Parent-Child in Grids</title><link>http://forum.strataframe.net/FindPost9454.aspx</link><description>Hi!&lt;/P&gt;&lt;P&gt;Yes this helped a lot!&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Sarosh</description><pubDate>Fri, 08 Jun 2007 19:39:10 GMT</pubDate><dc:creator>Sarosh</dc:creator></item><item><title>RE: Parent-Child in Grids</title><link>http://forum.strataframe.net/FindPost9448.aspx</link><description>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.&lt;br&gt;
&lt;br&gt;
[codesnippet]Private Sub parentBO_Navigated(ByVal sender As Object _&lt;br&gt;
                                       , e As Microfour.StrataFrame.Business.NavigatedEventArgs) Handles parentBO.Navigated&lt;br&gt;
  '-- Validate that there is a current row.&lt;br&gt;
  If Me.parentBO.CurrentRowIndex &lt; 0 Then Return&lt;br&gt;
  &lt;br&gt;
  '-- Get the parent ID&lt;br&gt;
  '    where PKField is the name of the PK field of the parent...&lt;br&gt;
  Dim id As Integer = Me.parentBO.PKField &lt;br&gt;
&lt;br&gt;
  '-- Load the child: two options&lt;br&gt;
  '    First, if there is a parent child relationship set for these BOs...&lt;br&gt;
  Me.childBO.FillByParentPrimaryKey(id)&lt;br&gt;
&lt;br&gt;
  '    Second, use your sproc fill method&lt;br&gt;
  Me.childBO.FillBySproc(id)&lt;br&gt;
End Sub[/codesnippet]&lt;br&gt;
&lt;br&gt;
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!</description><pubDate>Fri, 08 Jun 2007 15:06:25 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Parent-Child in Grids</title><link>http://forum.strataframe.net/FindPost9443.aspx</link><description>Hi!&lt;/P&gt;&lt;P&gt;Yes, by SP I meant Stored Procedure.&lt;/P&gt;&lt;P&gt;Thanks for the code that was exactly what I was looking for, just&amp;nbsp;one more thing, what should the code look like for a child BO so that it&amp;nbsp;retrieves only&amp;nbsp;rows for the current Parent's Key rather than retrieving all rows and then they get filtered on the client side.&lt;/P&gt;&lt;P&gt;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&amp;nbsp;rows that matched the Parent's Key.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sarosh</description><pubDate>Fri, 08 Jun 2007 13:59:21 GMT</pubDate><dc:creator>Sarosh</dc:creator></item><item><title>RE: Parent-Child in Grids</title><link>http://forum.strataframe.net/FindPost9438.aspx</link><description>I can help with 3] retrieving data using sprocs (assuming that's what SPs means!)&lt;br&gt;
&lt;br&gt;
In a fill method using code something like this:&lt;br&gt;
&lt;br&gt;
[codesnippet]Public Sub FillBySproc(ByVal paramValue As Integer)&lt;br&gt;
  Using cmd As New SqlCommand()&lt;br&gt;
    cmd.CommandType = Data.CommandType.StoredProcedure&lt;br&gt;
    cmd.CommandText = "sp_YourSproc"&lt;br&gt;
&lt;br&gt;
    '-- Setup parameters (add for any parameters needed by the sproc)&lt;br&gt;
    cmd.Parameters.Add("param1",Data.SqlDbType.Int)&lt;br&gt;
    cmd.Parameters("@param1").Value = paramValue ' Passed in value&lt;br&gt;
&lt;br&gt;
    '-- Load the data table&lt;br&gt;
    Me.FillDataTable(cmd)&lt;br&gt;
  End Using&lt;br&gt;
End Sub[/codesnippet]&lt;br&gt;
&lt;br&gt;
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.</description><pubDate>Fri, 08 Jun 2007 12:40:02 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>