Parent - child and SF ListView controls


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Bruce,

Thanks for all of your comments!  You are right about the code optimization within the sample, I just slapped it together so you would have a reference.  You are also right about using the automatic child filtering.  If you were coding witin an application you always want to make sure to make the least number of trips to the server as possible. But in some cases, like the demonstration, it is better to minimize the amount of data coming across the network.  Here within lies the logic in some cases, if you know for a fact that all of the child records need to be presented, then it is genearlly best to get all of the child records.  However, when working in a distributed network when there may be VPN clients or external clients using a middle tier server, then sometimes it is best to retrieve only the data that the end-user is currently inquiring about.  Otherwise you have more network traffic and a slower application.  So it really depends on what you are attempting to do.

In our medical application there are times for both schools of thought.  We are all about optimization and the most efficient way for the application to run.  In many cases it just doesn't makes sense to get all of the child records.

Thanks for your comment on my investigative work. Not only am I new to StrataFrame, but I'm also new to .NET, C#, VB.NET, MS Visual Studio and n-tier development. (I'm in the process of migrating from Delphi/Win32 development.) So you see, with so many learning curves to climb at once, I kinda need to make sure I'm going to make sense before I post a question (and not appear like a complete dummy).

You are doing a great job and it is good to see that you are really digging into the language and trying to understand the concepts behind the actions.  Kudos to you!

On that point, can I make a suggestion regarding your help file (the new one released last week). It is a great document, and it has helped a lot. But like most other help documents, including Microsoft's .NET documentation, it is big on telling us what things are, but fairly light on telling us the best way to use those things. In my experience you can never have too many examples on how to use the various classes and properties. In particular, a comprehensive guide to best practices from you guys would be invaluable.

Thanks for the input.  Our documentation is a living thing that continues to grow.  It is entirely our desire to provide as many articles and real world examples to help.  Now that the class reference is built, we will be adding documentation and code samples showing more detailed explanations of classes.  As you know and understand as a software developer, there is always more documentation to write.  This is always a good sign of a growing product!  Thanks again for all of your comments.

Bruce Palmer
Bruce Palmer
StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)
Group: Forum Members
Posts: 18, Visits: 33
Thanks for your reply Trent. You've confirmed that I was on the right track with my first method, i.e. using external business objects and the CopyDataFrom methods to get their data into the ListView internal business objects.



Thanks also for the example. It is very similar to my first method, with the one exception that you hit the database for new child objects every time the parent object is changed. This may be because you've cut and paste from a generic example, and that you're primarily trying to illustrate the CopyDataFrom method. It also may be exactly the behaviour required in some cases. My preference, however, would be to minimise database hits where possible.



I would make the following changes to your example. First, I would set the CustomersBO1.ChildAutoFilterOption property to MatchCurrentRow. Second, I would remove the Me.OrdersBO1.FillByParentPrimaryKey method call in the lvParent_SelectedIndexChanged event handler and replace it with:



Me.CustomersBO1.Navigate(MicroFour.StrataFrame.Business.BusinessNavigationDirection.Absolute, lvParent.SelectedItems(0).Index)



Finally, I would add the following line to the end of the Form1 constructor:



Me.OrdersBO1.FillByParent()



Now all the child data is retrieved in one hit on the database, and CustomersBO1 manages the filtering of OrdersBO1. Because lvChild uses CopyDataFrom with a second parameter of ClearAndFillFromDefaultView, when it calls Requery it only gets the filtered data, which is exactly what we want.



Of course there will be situations where one of these techniques is prefered over the other. It's all to easy (and I have been guilty of this) to cut and paste an example without understanding what it is actually doing. The example code may work, but it may not be the best answer for a given situation.



Thanks for your comment on my investigative work. Not only am I new to StrataFrame, but I'm also new to .NET, C#, VB.NET, MS Visual Studio and n-tier development. (I'm in the process of migrating from Delphi/Win32 development.) So you see, with so many learning curves to climb at once, I kinda need to make sure I'm going to make sense before I post a question (and not appear like a complete dummy).BigGrin



On that point, can I make a suggestion regarding your help file (the new one released last week). It is a great document, and it has helped a lot. But like most other help documents, including Microsoft's .NET documentation, it is big on telling us what things are, but fairly light on telling us the best way to use those things. In my experience you can never have too many examples on how to use the various classes and properties. In particular, a comprehensive guide to best practices from you guys would be invaluable.



Thanks,

Bruce

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Sorry for the stripping issue on the forum, this is just a limitation of the forum...at least for now Ermm

I am impressed with your investigative work!  Actually, the most effecient way to populate a ListView is going to be through the CopyDataFrom method which will maintain your relationships since an external BO is referenced.  In many of our classes, such as the ChildFormDialog and UserControl, we have a BO Translation table that will literally translate the internal references back to the original BO.  However, there are some issues when taking this same approach with a ListView.  First, it makes setting up the ListView more complicated since it is relying on an external reference.  Second, it is actually no more effecient than using the CopyDataFrom method....at least per our benchmark tests.  We provided the ability to at least access an external BO which has already been queried and relationships can be maintained.

I went ahead and created a sample for you to look at.  You can get to it from the link below.  Hope this helps! Smile

http://forum.strataframe.net/Topic2014-17-1.aspx?Update=1

Bruce Palmer
Bruce Palmer
StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)
Group: Forum Members
Posts: 18, Visits: 33
My issue with the source code formatting is that it keeps stripping out the leading tabs and/or spaces used for the indenting.
Bruce Palmer
Bruce Palmer
StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)StrataFrame Beginner (20 reputation)
Group: Forum Members
Posts: 18, Visits: 33
Hi guys. I'm currently evaluating StrataFrame. So far I'm quite impressed, though I'm still scrambling up the learning curve.Smile



If my understanding is correct, SF ListView controls each have an internal business object that is created upon creation of the control, and is of a type as specified by the PopulationDataSourceSettings property (assuming this property isn't blank).



I want to use two ListView controls on a form, lvParent for ParentBO and lvChild for ChildBO. I can't find a way to access the internal business objects of the ListView controls, so I cannot set the ParentBusinessObject property of the internal business object of lvChild to the internal business object of lvParent. This means that I can't use a relationship that has been defined in the ChildBO classes ParentRelationship property.



To get around this I drop a ParentBO and ChildBO on the form, set ChildBO.ParentBusinessObject to the ParentBO instance, set ParentBO.ChildAutoFilterOption to MatchCurrentRow, and then define the following event handlers.



private void parentBO_ParentFormLoading()

{

// Get all parent objects for the specified month.

parentBO.FillByDate(new DateTime(2006, 7, 1));

}



private void childBO_ParentFormLoading()

{

childBO.FillByParent();

}



private void lvParent_ListPopulating(MicroFour.StrataFrame.UI.ListPopulatingEventArgs e)

{

e.Parameters[0].Value = parentBO;

e.Parameters[1].Value = BusinessCloneDataType.ClearAndFillFromCompleteTable;

}





private void lvParent_SelectedIndexChanged(object sender, EventArgs e)

{

if ( (lvParent.SelectedItems.Count > 0) && (lvParent.SelectedItems[0].Tag != null) )

{

parentBO.Navigate(BusinessNavigationDirection.Absolute, lvParent.SelectedItems[0].Index);

lvChild.Requery();

}

else

{

lvChild.Items.Clear();

}

}



private void lvChild_ListPopulating(MicroFour.StrataFrame.UI.ListPopulatingEventArgs e)

{

e.Parameters[0].Value = childBO;

e.Parameters[1].Value = BusinessCloneDataType.ClearAndFillFromDefaultView;

}



Now this works fine. But, as the business objects internal to the ListView controls have copies of the data in the business objects on the form, if the business objects are large in size and/or number then there is inefficient use of memory.



An alternative method would be to delete the business objects on the form and the above event handlers, and use the following event handlers instead.



private void lvParent_ListPopulating(MicroFour.StrataFrame.UI.ListPopulatingEventArgs e)

{

// Get all parent objects for the specified month.

e.Parameters[0].Value = new DateTime(2006, 7, 1);

}



private void lvParent_SelectedIndexChanged(object sender, EventArgs e)

{

if ( (lvParent.SelectedItems.Count > 0) && (lvParent.SelectedItems[0].Tag != null) )

{

lvChild.Requery(lvParent.SelectedItems[0].Tag);

}

else

{

lvChild.Items.Clear();

}

}



This method uses memory efficiently, particularly as only chlid objects for the current parent object are in memory. The down side, of course, is that every time the parent object is changed a trip to the database is required to get the new child objects. The first method avoided this because it retrieved all the child objects in one go and was filtered as required.



Method 1 seems preferrable to me as it utilises the defined relationship in the business objects and reduces trips to the database. However I think it would be even better if I was able to link the internal business objects of the ListView controls using ParentBusinessObject. This would eliminate duplicate business objects and their contents. Is this possible or not? Have I missed something?



Thanks in advance,

Bruce



P.S. Pardon my ignorance, but how the heck to I properly format source snippets in a posting?!?

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