Treeview with 3 or 4 levels

Treeview with 3 or 4 levels

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


FireGarden posted on Sunday, August 13, 2006

I am trying to build a tree view to represent a heirachy of 3-4 levels. I would like to bind the tree view to either a single CSLA object or a bunch of lists. I am not really sure what my approach should be.

The tree view is going to be used for selection and for restructuring of the tree. Probably allow user to drag children to other parents as long as the parent is in the same level.

What is my best approach? I have tried using a namevalue list and dynamically creating new lists each time the user expands a node in the tree but I am getting into a nighmare wiht dynamically databinding the children and its just not working.

Perhaps I should just create a great-grandchild level deep object?

Any thoughts would be appreciated.

Regards,

Rob

 

Brian Criswell replied on Sunday, August 13, 2006

What I have found to be the best for me is to inherit TreeNode for each type of object represented in the TreeView.  Each type of TreeNode encapsulates one of the object types and listens to relevant events to simulate data binding.  The attached example may give you an idea as to where to go with it.  It contains a base TreeNode to handle some basic functionality, a base TreeNode that wraps a list and listens to the ListChanged event, and an example of implementing a concrete object.

FireGarden replied on Sunday, August 13, 2006

Brian I am all over this. I am downloading your sample now. Thanks for taking the time to respond.

Rob

CSLAer replied on Monday, August 14, 2006

Brian Criswell:
What I have found to be the best for me is to inherit TreeNode for each type of object represented in the TreeView.  Each type of TreeNode encapsulates one of the object types and listens to relevant events to simulate data binding.  The attached example may give you an idea as to where to go with it.  It contains a base TreeNode to handle some basic functionality, a base TreeNode that wraps a list and listens to the ListChanged event, and an example of implementing a concrete object.

Hi,

I'm truggling the treeview also. I'm new to C# & CSLA. Do you mind give me more details about your code? I've downloaded, but can not compile.

FireGarden replied on Monday, August 14, 2006

The code does not compile. You will have to try an understand the concepts behind what Brian is trying to accomplish. I will post my code when I get it going.

Brian I am having a little trouble as well. I believe the listNodes class is to be used as a base classs but I don't understand your usage of

ProjectTreeNode : ObjectTreeNodeBase<Library.Project>

Could you post this class? Does it consume ListNodeBase in any way?

Rob

Brian Criswell replied on Monday, August 14, 2006

Sorry for the incomplete example.  It was late and I just grabbed a few files.

FireGarden replied on Tuesday, August 15, 2006

The example is great except I would love to get my hands on "ObjectTreeNodeBase<>" so I don't have to reinvent the wheel...

*EDIT*

Also what is the datatype behind Library.Assembly? is it a business object?

Rob

 

 

Brian Criswell replied on Wednesday, August 16, 2006

Sorry about that.  I had written this code a few months ago and thought that TreeNodeBase was sufficient.  Yes, Assembly is a business object in my application.  The AssemblyList is a list of them.

FireGarden replied on Wednesday, August 16, 2006

Thanks Brain. TreeNodeBase was probably sufficient now looking at it. Still your solution was very helpful.

Rob

ljcorreia replied on Wednesday, November 21, 2007

Hi,

It has been a while since this thread was posted, but I came across this just now while I was looking for something related to bind business objects and its lists in a treeview. Seems to be a smart solution and very useful. Thanks for post your code Brian and also thanks for the ObjectListView also used in this implementation.
Brian, I read your last post on this forum, so I know you are very busy at the moment with big changes in your life (btw, congrats for the baby !), so I was wondering if you can help me.

I was trying to accomplish a similar scenario, binding csla business objects to a TreeView, but in a Web Envirownment using ASP.NET with C#. What I did 'til now was convert your classes (ListTreeNodeBase.cs, ObjectTreeNodeBase.cs, TreeNodeBase.cs) trying my best to understand it, once I don't have too much experience in CSLA and OO programming expertise. Also I rebuild the csla.dll including your ObjectListView classes that I found:  http://forums.lhotka.net/forums/thread/4666.aspx

Rob, you commented something about post your code after finish it. Did you manage to get it working?

Everything is compiling 'til this point. Beyond that, I found AssemblyListTreeNode.cs, AssemblyTreeNode.cs and ProjectTreeNode.cs that I'm not sure how to use.
I suppose I should do something similar to wrap my own business objects, right?

Can you help me giving some examples how to consume this objects, including expose some object in a TreeVew in the UI ?

Leonardo

Copyright (c) Marimer LLC