Click here to Skip to main content
6,306,412 members and growing! (17,245 online)
Email Password   helpLost your password?
General Programming » Algorithms & Recipes » General     Intermediate

Bind Nested Tree view from database

By Ritesh Sutaria

Bind Nested Tree View
C#, Windows, .NET, Visual Studio, Dev
Posted:28 Aug 2006
Views:31,947
Bookmarked:12 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
10 votes for this article.
Popularity: 1.46 Rating: 1.46 out of 5
7 votes, 70.0%
1
2 votes, 20.0%
2

3

4
1 vote, 10.0%
5

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


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.
Location: India India

Other popular Algorithms & Recipes articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 28 (Total in Forum: 28) (Refresh)FirstPrevNext
General2 Pinmembermmiesi5:47 24 Jul '07  
General2.1 Pinmembermmiesi5:47 24 Jul '07  
General2.1.1 Pinmembermmiesi5:48 24 Jul '07  
General2.1.2 Pinmembermmiesi5:49 24 Jul '07  
General2.2 Pinmembermmiesi5:48 24 Jul '07  
Generalnested ul Pinmembermmiesi23:46 15 Jul '07  
General1 Pinmembermmiesi23:06 15 Jul '07  
General1.1 Pinmembermmiesi23:07 15 Jul '07  
General1.1.1 Pinmembermmiesi23:07 15 Jul '07  
General1.1.2 Pinmembermmiesi23:18 15 Jul '07  
General1.1.2.1.1 Pinmembermmiesi23:20 15 Jul '07  
General1.1.2.1.1.1 Pinmembermmiesi23:21 15 Jul '07  
General1.1.2.1.1.1.1 Pinmembermmiesi23:22 15 Jul '07  
General1.1.2.1.1.1.1.1 Pinmembermmiesi23:22 15 Jul '07  
General1.1.2.1.1.1.1.1.1 Pinmembermmiesi23:22 15 Jul '07  
GeneralRe: 1.1.2.1.1.1.1.1.1.1 Pinmembermmiesi23:23 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1 Pinmembermmiesi23:23 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1 Pinmembermmiesi23:23 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi23:24 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi23:25 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi23:26 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi23:26 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi23:27 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi23:28 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1 Pinmembermmiesi23:29 15 Jul '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 28 Aug 2006
Editor:
Copyright 2006 by Ritesh Sutaria
Everything else Copyright © CodeProject, 1999-2009
Web13 | Advertise on the Code Project