Click here to Skip to main content
Licence 
First Posted 28 Aug 2006
Views 53,610
Bookmarked 16 times

Bind Nested Tree view from database

By | 28 Aug 2006 | Article
Bind Nested Tree View

Sample Image - Bind_Nested_Tree_View.jpg

Introduction

This is an example of how to bind a nested tree from database.

Very Simple algorithm to bind tree.

method insertnodes is called recursively which will bind a nested tree at n level

create one table in access with following fields

module_id        integer

module_name   varchar(50)

parent_module    integer

place one treeview control, and call this method with first parameter null 

insertnodes(null,0);

private void insertnodes ( TreeNode n , int module_id )

{

OleDbConnection con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\tree.mdb");

con.Open();

OleDbCommand cmd=new OleDbCommand( "SELECT * FROM [module] WHERE parent_module=" + module_id,con);

OleDbDataReader rdr=cmd.ExecuteReader();

while(rdr.Read())

{

TreeNode t=new TreeNode(rdr["module_name"].ToString());

insertnodes(t,Convert.ToInt16(rdr["module_id"].ToString()));

if(n==null)

treeView1.Nodes.Add(t);

else

n.Nodes.Add(t);

}

rdr.Close();

}

 

source code is included which can be useful to understand the code 

regards,

ritesh

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Ritesh Sutaria



India India

Member

Ritesh Sutaria has about 7+ years of IT experience on various technologies like ASP.net, PHP, VB, Oracle, PGSql, Sql Server. He has worked on various platforms including Windows, Linux. He has a powerfull problem solving skills which actually makes complex problems into simple problems.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questioncool Pinmembertomicekpetr5:04 9 Jul '11  
GeneralMy vote of 5 Pinmembergautam.munish@gamil.com20:10 5 Jul '11  
General2 Pinmembermmiesi4:47 24 Jul '07  
General2.1 Pinmembermmiesi4:47 24 Jul '07  
General2.1.1 Pinmembermmiesi4:48 24 Jul '07  
General2.1.2 Pinmembermmiesi4:49 24 Jul '07  
General2.2 Pinmembermmiesi4:48 24 Jul '07  
Generalnested ul Pinmembermmiesi22:46 15 Jul '07  
Sorry for the previous experiment, I need to implement similar menu for the discussion and i was trying to figure out how did the codeproject team came with their solution. Interesting is that all the response message are shifted to the right with various margin (looks like depends on the power of nested level) and finally all would come in almost one vertical line. I will appreciate any clue for doing this in asp.net (preferably not using treeview component, because of code customization) assuming that all the comments are stored in one database table which has relation to itself for finding the previous comment (when relation is not set, this is the first post).
 
Sorry for my english,
Best,
Mariusz.
 
P.S - hopefully moderation will have mercy, and let stay this example for good of science : ) until somebody come with solution - it's just a one topic that can be deleted easily with a click.
 
Thank you.
General1 Pinmembermmiesi22:06 15 Jul '07  
General1.1 Pinmembermmiesi22:07 15 Jul '07  
General1.1.1 Pinmembermmiesi22:07 15 Jul '07  
General1.1.2 Pinmembermmiesi22:18 15 Jul '07  
General1.1.2.1.1 Pinmembermmiesi22:20 15 Jul '07  
General1.1.2.1.1.1 Pinmembermmiesi22:21 15 Jul '07  
General1.1.2.1.1.1.1 Pinmembermmiesi22:22 15 Jul '07  
General1.1.2.1.1.1.1.1 Pinmembermmiesi22:22 15 Jul '07  
General1.1.2.1.1.1.1.1.1 Pinmembermmiesi22:22 15 Jul '07  
GeneralRe: 1.1.2.1.1.1.1.1.1.1 Pinmembermmiesi22:23 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1 Pinmembermmiesi22:23 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1 Pinmembermmiesi22:23 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi22:24 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi22:25 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi22:26 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi22:26 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi22:27 15 Jul '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120529.1 | Last Updated 28 Aug 2006
Article Copyright 2006 by Ritesh Sutaria
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid