StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Hierarchal data and tree viewsExpand / Collapse
Author
Message
Posted 10/30/2006 2:38:20 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Today @ 11:34:55 AM
Posts: 1,327, Visits: 3,472
I'm not sure if this is the best place for this question or in the BusinessObjects section...

I have several hierarchal data structures and would like to present them in a tree view. Some of these structures are from within a single table and some span multiple tables. I looking for any suggestions, guidelines on the best way to do this. I'm assuming that in any case I'm likely going to be getting a DataTable from a BO and manually building the tree, but maybe there is a better way.

So, the two types of hierarchies are:

1. parent child within a single table
2. parent child within a single table and with children within another table

So, how best to implement this sort of thing?
Post #3990
Posted 10/30/2006 2:52:41 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 10:13:07 AM
Posts: 4,799, Visits: 4,768
TreeViews are a wonderful tool in .NET and we use them all over the place...however, though there are similarities between each use, the TreeView is always a little bit different, thus making it a little more difficult to have a hard and fast standard.

Here are some of the standards that we follow though.  The best advice is to create recursive methods that build each of the nodes.

Private Sub LoadTree()
    '-- Establish Locals
    Dim loNode As TreeNode

    '-- Clear the tree
    MyTreeView.Nodes.Clear()

    '-- Cycle through all of the parent records
    If MyBO.MoveFirst()
         Do
              '-- Create the new root node
              loNode = New TreeNode(MyBO.MyTitleField)

              '-- Load any children nodes
              LoadChildNodes(MyBO, loNode)
         Loop While MyBO.MoveNext()
    End If
End SUb

Private Sub LoadChildNodes(Byval ParentBO As BusinessLayer, Byval ParentNode As TreeNode)
    '-- Establish Locals
    Dim loNode As TreeNode
    Dim loChildBO As New MyChildBO

    '-- Load the child records
    loChildBO.FillByParentPrimaryKey(ParentBO.PrimaryKey)

    '-- Cycle through the child nodes
    If loChildBO.MoveFirst()
        Do
            '-- Create the node
            loNode = New TreeNode(loChildBO.TitleField)

            '-- Add to parent nodes
            ParentNode.Nodes.Add(loNode)

            '-- Check for child nodes
            If loChildBO.HasChildRecords Then
                  LoadChildNodes(loChildBO, loNode)
            End If
        Loop While loChildBO.MoveNext()
    End If

    '-- Clean Up
    loChildBO.Dispose()
End Sub

Also, we generally create a class and store it in the tag property of each node so that when it is clicked we know exactly what to do.  You can see a simple example of this in the samples that were installed with the framework.  I think it is called Explorer Form Sample.

Post #3992
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 12:19pm

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.125. 16 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.