J
jayson_13
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)
}
}
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)
}
}