By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,193 Members | 1,734 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,193 IT Pros & Developers. It's quick & easy.

hierarchical implementation question

P: n/a
Hi,

I want to retrieve the hierarchical structure which is store inside
the database and then display it using treeview control. But now I
got a design issue which I hope that you guys can help me. My
hierarchical structure has five levels which is store in table call
level1, level2, level5. Each level remember the parent ID e.g. level5
contains a column called level4ID. How should I implement it in order
to get fastest loading?
Currently what I think of is that fill the records in level1,
level2, level3, level4, level5 into the same dataset. Then use nested
loop to implement the treeview.
Can anyone give me more efficient solution? Seems like I am a stupid
programmer.

foreach(DataRow dr in dsAcctChart.Tables[Level1].Rows)
{
treeview1.Nodes.Add(dr["Name"].ToString());
DataRow [] drows=dsAcctChart.Tables[Level2].Select("Level1ID=" +
dr["ID"].ToString());
foreach(DataRow dr1 in drows)
{
if(treeView1.SelectedNode == null)
treeView1.SelectedNode=treeView1.Nodes[Level1NodeCount];
treeView1.SelectedNode.Nodes.Add(dr1["Name"].ToString());
foreach(..Level3)
.
foreach(.Level4)
..
foreach( Level5)
}
}
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"jayson_13" <ja*******@yahoo.com> wrote in message
news:85**************************@posting.google.c om...
Hi,

I want to retrieve the hierarchical structure which is store inside
the database and then display it using treeview control. But now I
got a design issue which I hope that you guys can help me. My
hierarchical structure has five levels which is store in table call
level1, level2,. level5. Each level remember the parent ID e.g. level5
contains a column called level4ID. How should I implement it in order
to get fastest loading?
Currently what I think of is that fill the records in level1,
level2, level3, level4, level5 into the same dataset. Then use nested
loop to implement the treeview.
Can anyone give me more efficient solution? Seems like I am a stupid
programmer.


Loading data-heavy tree-views can be tricky and time-consuming. There's two
things I do which may apply to your situation.

1. Lazy-Loading - on form load, load only the top level treeview nodes.
Then, hook the expand event so that whan the user expands a node, you
quickly load its child nodes from the database and insert them into the
tree. I usually pin data to the Tag of each TreeNode which tells me what
information needs to be loaded for the children of that node. SqlBuddy
(http://sqlbuddy.sourceforge.net) uses this approach to load in the Database
Explorer - and it's pretty darn quick! You can see the idea in the link
below( watch for breaks) - look for the HandleExplandNode function about 1/4
down the page:

http://cvs.sourceforge.net/viewcvs.p...viewcvs-markup

2. Freezing the View - by visually freezing the view and showing an
hourglass, you can at least reduce the impression that loading of the tree
is slow. I think a flickering tree makes the user very aware that things are
taking time! In buddy I used a WinAPI call to freeze the tree as it is
cleared and reloaded. Again, you can see this in the first two lines of the
HandleExpandNode method.

Hope this helps

Tobin Harris
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.