﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum / StrataFrame Application Framework / WinForms (How do I?)  / Hierarchal data and tree views / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>forum@strataframe.net</webMaster><lastBuildDate>Wed, 07 Jan 2009 18:33:46 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Hierarchal data and tree views</title><link>http://forum.strataframe.net/Topic3990-7-1.aspx</link><description>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.&lt;/P&gt;&lt;P&gt;Here are some of the standards that we follow though.  The best advice is to create recursive methods that build each of the nodes.&lt;/P&gt;&lt;P&gt;Private Sub LoadTree()&lt;BR&gt;    '-- Establish Locals&lt;BR&gt;    Dim loNode As TreeNode&lt;BR&gt;&lt;BR&gt;    '-- Clear the tree&lt;BR&gt;    MyTreeView.Nodes.Clear()&lt;BR&gt;&lt;BR&gt;    '-- Cycle through all of the parent records&lt;BR&gt;    If MyBO.MoveFirst()&lt;BR&gt;         Do&lt;BR&gt;              '-- Create the new root node&lt;BR&gt;              loNode = New TreeNode(MyBO.MyTitleField)&lt;BR&gt;&lt;BR&gt;              '-- Load any children nodes&lt;BR&gt;              LoadChildNodes(MyBO, loNode)&lt;BR&gt;         Loop While MyBO.MoveNext()&lt;BR&gt;    End If&lt;BR&gt;End SUb&lt;/P&gt;&lt;P&gt;Private Sub LoadChildNodes(Byval ParentBO As BusinessLayer, Byval ParentNode As TreeNode)&lt;BR&gt;    '-- Establish Locals&lt;BR&gt;    Dim loNode As TreeNode&lt;BR&gt;    Dim loChildBO As New MyChildBO&lt;BR&gt;&lt;BR&gt;    '-- Load the child records&lt;BR&gt;    loChildBO.FillByParentPrimaryKey(ParentBO.PrimaryKey)&lt;BR&gt;&lt;BR&gt;    '-- Cycle through the child nodes&lt;BR&gt;    If loChildBO.MoveFirst()&lt;BR&gt;        Do&lt;BR&gt;            '-- Create the node&lt;BR&gt;            loNode = New TreeNode(loChildBO.TitleField)&lt;BR&gt;&lt;BR&gt;            '-- Add to parent nodes&lt;BR&gt;            ParentNode.Nodes.Add(loNode)&lt;BR&gt;&lt;BR&gt;            '-- Check for child nodes&lt;BR&gt;            If loChildBO.HasChildRecords Then&lt;BR&gt;                  LoadChildNodes(loChildBO, loNode)&lt;BR&gt;            End If&lt;BR&gt;        Loop While loChildBO.MoveNext()&lt;BR&gt;    End If&lt;BR&gt;&lt;BR&gt;    '-- Clean Up&lt;BR&gt;    loChildBO.Dispose()&lt;BR&gt;End Sub&lt;/P&gt;&lt;P&gt;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.</description><pubDate>Mon, 30 Oct 2006 14:52:41 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>Hierarchal data and tree views</title><link>http://forum.strataframe.net/Topic3990-7-1.aspx</link><description>I'm not sure if this is the best place for this question or in the BusinessObjects section...&lt;br&gt;&lt;br&gt;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.&lt;br&gt;&lt;br&gt;So, the two types of hierarchies are:&lt;br&gt;&lt;br&gt;1. parent child within a single table&lt;br&gt;2. parent child within a single table and with children within another table&lt;br&gt;&lt;br&gt;So, how best to implement this sort of thing?</description><pubDate>Mon, 30 Oct 2006 14:38:20 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>