5,666,979 members and growing! (15,727 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
Updated: 28 Aug 2006
Views: 23,713
Bookmarked: 9 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
10 votes for this Article.
Popularity: 1.46 Rating: 1.46 out of 5
7 votes, 70.0%
1
2 votes, 20.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
1 vote, 10.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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


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
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 27 (Total in Forum: 27) (Refresh)FirstPrevNext
General2membermmiesi5:47 24 Jul '07  
General2.1membermmiesi5:47 24 Jul '07  
General2.1.1membermmiesi5:48 24 Jul '07  
General2.1.2membermmiesi5:49 24 Jul '07  
General2.2membermmiesi5:48 24 Jul '07  
Generalnested ulmembermmiesi23:46 15 Jul '07  
General1membermmiesi23:06 15 Jul '07  
General1.1membermmiesi23:07 15 Jul '07  
General1.1.1membermmiesi23:07 15 Jul '07  
General1.1.2membermmiesi23:18 15 Jul '07  
General1.1.2.1.1membermmiesi23:20 15 Jul '07  
General1.1.2.1.1.1membermmiesi23:21 15 Jul '07  
General1.1.2.1.1.1.1membermmiesi23:22 15 Jul '07  
General1.1.2.1.1.1.1.1membermmiesi23:22 15 Jul '07  
General1.1.2.1.1.1.1.1.1membermmiesi23:22 15 Jul '07  
GeneralRe: 1.1.2.1.1.1.1.1.1.1membermmiesi23:23 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1membermmiesi23:23 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1membermmiesi23:23 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1membermmiesi23:24 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1membermmiesi23:25 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1membermmiesi23:26 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1membermmiesi23:26 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1membermmiesi23:27 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1membermmiesi23:28 15 Jul '07  
General1.1.2.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1membermmiesi23: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-2008
Web17 | Advertise on the Code Project