Binding BOs to Tree View control?

Binding BOs to Tree View control?

Old forum URL: forums.lhotka.net/forums/t/2102.aspx


maurera posted on Tuesday, January 09, 2007

We have a need to have a BO that can bind to a Tree View control.  Perhaps my “Google Fu” is week, but I was unable to find a solution on CLSA Contrib, or these forums and was hoping someone could point us in the right direction.

 

Let me give you guys a little background.  We are creating a Recipe management application.  The design calls for a form that will contain a tree view control “coupled” with a list box control which will be used primarily for navigation; similar to how the windows explorer works except the Tree View control will display a list of Recipes and Sub Recipes instead of folders, and the List Box control will display a list of ingredient(s), Package(s), and Step(s) associated with the currently selected recipe in the Tree View control, instead of a list of files contained within the currently selected folder.

 

A key concept here is that a Recipe will contain Sub Recipe(s) which, themselves, can also contain sub recipe(s) and so on to the n level.  Further complicating the scenario (although I don’t think it is relevant to the discussion) is that a Sub Recipe can be contained within multiple Sub Recipes that are part of the same parent Recipe…let me explain.  Recipe A contains recipe B and C as Sub Recipes.  Recipe C contains Sub Recipe D as one of its Sub Recipes.  Both Recipe B and Recipe D contain Recipe E as one of their sub recipes.

 

I believe we have come up with a conceptually sound design to accomplish the “recipe explorer”, where the TreeView control will be bound to a “RecipeHierarchy” object.  The “Companion ListBox” will be bound to a filterable, bindable, list object called “RecipePartList”.  Clicking on a Node in the Tree would filter the RecipePartList by the RecipeID of that node.

 

The problem we are facing is, how would we go about binding the “RecipeHierarchy” object to a tree view or, more generically, how would you create an object that is able to be bound to a Tree View?

 

Please keep in mind that we are a VB .NET shop.

 

Thanks in advance,

Adam

skagen00 replied on Tuesday, January 09, 2007

I created heirarchical coding for use with Csla, and I ended up implementing some interfaces...

Google for IHierarchicalDataSource and I suspect you may find what you're looking for.

 

skagen00 replied on Tuesday, January 09, 2007

by the way, this interface appears to be directed towards ASP.Net. Hope that's what you need it for :).

maurera replied on Tuesday, January 09, 2007

I was just about to respond to you regarding that very same subject.  The application is a windows application, so I don't think we can use the interface.  I am in the process of researching this further to see if it can work for a windows Tree View control.  It would strike me as very odd that Microsoft would not provide some sort of bindable interface for a Windows tree view control.  Also, I would be very suprised if someone else using the CSLA would not need the same functionality...

Brian Criswell replied on Tuesday, January 09, 2007

Do a search of the forums for TreeNode.  I will be out of contact for the rest of the week, but I may be able to help next week.

Also, send a private message to FireGarden, as I think he implemented a version of this from my examples.

maurera replied on Tuesday, January 09, 2007

one step ahead of ya ;-)

I already did a search on TreeNode.  The results were somewhat helpful and led me down the path of creating the TreeNodeBase, ObjectTreeNodeBase, and ListTreeNodeBase classes.  The only code I was able to find was C# code, which I was able to translate into VB.NET with relative ease.  I did however run into a road block as the ListTreeNodeBase class was inheriting from ObjectListView which is a much more complex class written in C# created by Brain Criswell for the CSLA community.

I have posted a reply to his latest Update thread asking him if there is a VB.NET version of this code as we don't currently have time to "re-invent" the wheel (as it is we have spent more time then we want on this problem).  He just responded not that long ago that, once the class(es) is(are) stable, he would be providing a VB.NET version.  Unfortunately for us, his timeline for that (2-3 weeks at lest) is a little outside of our needs.  His suggestion to create a CSLA C# build that would reference the CLSA VB build was our only option and in fact was a point of discussion when we received his respone.  And then...

One of us was able to find a third party vendor (Infragistics) that has a windows tree control which supports the IList(of T), IBindingList interfaces...although I feel WEEEAK resorting to this solution, it is the path of least resistance since we should be able to use objects that inherit the SortedBindingList class as datasources directly (without having to jump through any hoops).

Hey man, I want to thank you for taking the time out of your day to look at this with us.  It is very much appreciated.  If you think of anything else feel free to post it hear for the benefit of others that have the same problem and aren't WEAK (or more accurately have the time on their hand to not be WEAK) heh heh.

On a side note:

 

Admittedly, I still wasn’t clear exactly how the Databinding was occurring using these classes and I was looking forward to finding out.  Once I have some “spare” time on my hands I think I would like to play around a bit more with this concept, as I think knowledge of how to provide a solution would be helpful to say the least.

 

It looked to me, without actually having a working set of classes, that the “TreeNode” classes were hooked into the list objects property changed events to directly manipulate the Windows Tree View control…does this sound right?

Further Side Note (Upon Edit):

heh heh, I didn't even realize I was responding to you Brian, but thank you as well :-)

Brian Criswell replied on Wednesday, January 10, 2007

By the way, you do not need the ObjectListView to make this system work.  You could just give it an array or List of your business object.  The only reason I used it was because I had a single list of objects that were used as the children of nodes and I used the filters to show which items belonged to which parent nodes.  So if you were loading a hierarchical list that already had the children joined to the correct parent, you would not need it.

maurera replied on Wednesday, January 10, 2007

Good timing :-)

We just finished up a design session where we came to the same conclusion.  Your ObjectListView would be helpful for our "PartsList" though.  Our Hierarchy Parent Child structure will be directly bindable to the Infragistics Tree View control as is (since the BuisnessListBase class inherits from System.ComponentModel.BindingList which in turn implements the interfaces required by the Infragistics Tree View Control for binding), without the need of filtering.

However, our "PartList" will be filtered to all parts except item type recipe (Ingredient, Package, Step) when bound to the "companion list box".  That being said, we also have a need to bind the "PartList" to a grid on a separate tab (in the same form) called components.  Under this context, the "PartList" will need to be filtered to display only item types Ingredient and Recipe.  Similarly there will be two other tabs "Packages" and "Steps" that need to filter the list based on Item Type Package and Steps respectively.

Not a day goes by that I don't admire the inherent beauty of the CSLA heh heh.

 

Copyright (c) Marimer LLC