home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
General Forums
OffTopic
Programming Logic
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="DieBagger" data-source="post: 540416" data-attributes="member: 56421"><p>Maybe I'm overlooking something here but to me this sounds like what you're searching for is recursion...</p><p></p><p>Let me try if I can write some pseudo code:</p><p></p><p></p><p>[CODE]</p><p>public void Main()</p><p>{//entry point</p><p> TreeNode rootNode = new TreeNode("I am root");</p><p> GetSubNodes(0, rootNode);</p><p>}</p><p></p><p>public void GetSubNodes(int _id, TreeNode _node)</p><p>{</p><p> List<Category> subCategories = GET_SUB_FROM_SQL(_id);//get the sub-categories from sql</p><p></p><p> foreach(Category c in subCategories)</p><p> {</p><p> TreeNode node = new TreeNode(c.category_name);</p><p> node.Tag = c;</p><p> GetSubNodes(c.category_id, node);//this is the recursion</p><p> _node.SubNodes.Add(c);</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p></p><p>Fyi it's already late and I'm sure there's something wrong with the code but it should give you the idea <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink ;)" loading="lazy" data-shortname=";)" /></p></blockquote><p></p>
[QUOTE="DieBagger, post: 540416, member: 56421"] Maybe I'm overlooking something here but to me this sounds like what you're searching for is recursion... Let me try if I can write some pseudo code: [CODE] public void Main() {//entry point TreeNode rootNode = new TreeNode("I am root"); GetSubNodes(0, rootNode); } public void GetSubNodes(int _id, TreeNode _node) { List<Category> subCategories = GET_SUB_FROM_SQL(_id);//get the sub-categories from sql foreach(Category c in subCategories) { TreeNode node = new TreeNode(c.category_name); node.Tag = c; GetSubNodes(c.category_id, node);//this is the recursion _node.SubNodes.Add(c); } } [/CODE] Fyi it's already late and I'm sure there's something wrong with the code but it should give you the idea ;) [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
General Forums
OffTopic
Programming Logic
Contact us
RSS
Top
Bottom