Click here to Skip to main content
Licence 
First Posted 28 Aug 2006
Views 51,588
Downloads 485
Bookmarked 16 times

Bind Nested Tree view from database

Bind Nested Tree View
8 votes, 61.5%
1
2 votes, 15.4%
2

3
1 vote, 7.7%
4
2 votes, 15.4%
5
1.26/5 - 13 votes
2 removed
μ 1.64, σa 2.84 [?]

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 Pinmembertomicekpetr6:04 9 Jul '11  
GeneralMy vote of 5 Pinmembergautam.munish@gamil.com21:10 5 Jul '11  
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  

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
Web04 | 2.5.120210.1 | Last Updated 28 Aug 2006
Article Copyright 2006 by Ritesh Sutaria
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid