Parent - child and SF ListView controls


Author
Message
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?!?

Replies
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.
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

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