hierarchical implementation question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jayson_13

    #1

    hierarchical implementation question

    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.Tab les[Level1].Rows)
    {
    treeview1.Nodes .Add(dr["Name"].ToString());
    DataRow [] drows=dsAcctCha rt.Tables[Level2].Select("Level1 ID=" +
    dr["ID"].ToString());
    foreach(DataRow dr1 in drows)
    {
    if(treeView1.Se lectedNode == null)
    treeView1.Selec tedNode=treeVie w1.Nodes[Level1NodeCount];
    treeView1.Selec tedNode.Nodes.A dd(dr1["Name"].ToString());
    foreach(..Level 3)
    ….
    foreach(….Level 4)
    …..
    foreach(… Level5)
    }
    }
  • Tobin Harris

    #2
    Re: hierarchical implementation question

    "jayson_13" <jayson_13@yaho o.com> wrote in message
    news:856e7de4.0 310011946.727f1 8a2@posting.goo gle.com...[color=blue]
    > 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.[/color]

    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 HandleExplandNo de function about 1/4
    down the page:

    Download SqlBuddy for free. SqlBuddy is a tool for use with Microsoft SQL Server and MSDE, written in csharp/ DotNet (.NET), to facilitate SQL script writing. It is serves a slightly different purpose that of Query Analyser, in that it is aimed to *help* the user write SQL.


    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
    HandleExpandNod e method.

    Hope this helps

    Tobin Harris


    Comment

    Working...