|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
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
IntroductionThis 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
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||