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

loading a treeeview from Database

P: n/a
Hi,

I am trying to load my items from Database to a Treeview but i have faild

My table contains id, parentId, nodeName like following:

(1 , 1 RootNode)

(2 , 2 , ParentNode)

(3, 2 , Child_for_2)

(4, 4 , AnotherParent)

(5 , 2 , anotherChild_for_2)

(6 , 4 , Child_for_4)

My problem is ,how i can create a treeview from this rows ( need some code).

here is a bit of my code what i have been trying for 6 hours.

try
{
treeView.BeginUpdate();
DataSet DS = new DataSet();
DS = MyWebService.LoadTreeViewFromDB();
if (DS != null)
{
TreeNode Root = new TreeNode("Taxonomy");
Root.Tag = 1;
treeView.Nodes.Add(Root);
TreeNode ParentNode = null;

foreach (DataRow DR in DS.Tables["folksonomy"].Rows)
{
TreeNode NewNode = new TreeNode();

if (DR["id"].ToString() == DR["parentid"].ToString())
{
NewNode.Text = DR["nodename"].ToString();
NewNode.Tag = DR["id"].ToString();
Root.Nodes.Add(NewNode);
}

else
{
foreach (DataRow ChildDataRow in DS.Tables["folksonomy"].Rows)
{
if (ChildDataRow["id"].ToString() == DR["parentid"].ToString())
{
I dont know what i should write here
}
}
}

}
}
May 10 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hello Medes,

See sample there http://www.codeproject.com/cs/miscct...02#xx1169975xx

BTW, why not to use XML for this, like over there http://support.microsoft.com/default...b;en-us;308063
M> Hi,
M>
M> I am trying to load my items from Database to a Treeview but i have
M> faild
M>
M> My table contains id, parentId, nodeName like following:
M>
M> (1 , 1 RootNode)
M>
M> (2 , 2 , ParentNode)
M>
M> (3, 2 , Child_for_2)
M>
M> (4, 4 , AnotherParent)
M>
M> (5 , 2 , anotherChild_for_2)
M>
M> (6 , 4 , Child_for_4)
M>
M> My problem is ,how i can create a treeview from this rows ( need some
M> code).
M>
M> here is a bit of my code what i have been trying for 6 hours.
M>
M> try
M> {
M> treeView.BeginUpdate();
M> DataSet DS = new DataSet();
M> DS = MyWebService.LoadTreeViewFromDB();
M> if (DS != null)
M> {
M> TreeNode Root = new TreeNode("Taxonomy");
M> Root.Tag = 1;
M> treeView.Nodes.Add(Root);
M> TreeNode ParentNode = null;
M> foreach (DataRow DR in DS.Tables["folksonomy"].Rows)
M> {
M> TreeNode NewNode = new TreeNode();
M> if (DR["id"].ToString() == DR["parentid"].ToString())
M> {
M> NewNode.Text = DR["nodename"].ToString();
M> NewNode.Tag = DR["id"].ToString();
M> Root.Nodes.Add(NewNode);
M> }
M> else
M> {
M> foreach (DataRow ChildDataRow in DS.Tables["folksonomy"].Rows)
M> {
M> if (ChildDataRow["id"].ToString() == DR["parentid"].ToString())
M> {
M> I dont know what i should write here
M> }
M> }
M> }
M> }
M> }
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
May 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.