J
John Rogers
I had given up on this for a while, but I am attempting it again.
This is what i am using to store my treeview layout into a db, I
am only using a few fields to make it easier to understand while
I am attempting to restore it back into the tree.
Text "Parent0", Level 0
Text "Child0", Level 1
Text "SubChild0", Level 2
Now I have read many posts where others are saying to store a unique
id
of the parent. I am having a bit of trouble trying to store an id
somewhere
and retrieve it on the next loop.
This is what I am looking at in the debugger, I am looking for
something that
I can use that is unique. This is a multilayer, many roots and many
nested nodes
in the treeview. This is just a sample I am posting.
//-------------------- Debugger values ------------------------------
+ Parent null System.Windows.Forms.TreeNode
Text "Parent0" string
Level 0 int
+ FirstNode {Text = "Child0"} System.Windows.Forms.TreeNode
+ NextNode {Text = "Parent1"} System.Windows.Forms.TreeNode
+ NextVisibleNode {Text = "Child0"} System.Windows.Forms.TreeNode
+ Parent {Text = "Parent0"} System.Windows.Forms.TreeNode
Text "Child0" string
Level 1 int
+ FirstNode {Text = "SubChild0"} System.Windows.Forms.TreeNode
+ NextNode null System.Windows.Forms.TreeNode
+ NextVisibleNode {Text = "SubChild0"} System.Windows.Forms.TreeNode
+ Parent {Text = "Child0"} System.Windows.Forms.TreeNode
Text "SubChild0" string
Level 2 int
+ FirstNode {Text = "SubSubChild0"} System.Windows.Forms.TreeNode
+ NextNode null System.Windows.Forms.TreeNode
+ NextVisibleNode {Text = "SubSubChild0"}
System.Windows.Forms.TreeNode
//-------------------- Debugger values ------------------------------
Lets say I start the loop, my first node will be "Parent0" it does not
have a parent, its a
rootnode, the ParentID for this will be NULL. On th next round I come
up with "Child0"
and that node has a parent which is "Parent0". Now how would I
generate a GUID for
Parent0, and tell Child0 who its parent is? Even if I create an
instance of my struct and store
the information in the struct. That information will be lost on my
next round of the loop because
I have to create a new instance of the struct again.
I am pretty confused right now, maybe I am over analyzing everything
and thats why i cant
get anything to work. Here is some sample code that leads to nowhere.
SaveTreeViewRecords SaveRecords = new
SaveTreeViewRecords();
foreach (TreeNode node in TreeView1.Nodes)
{
SaveRecords.SaveDBRecords(node);
}
class SaveTreeViewRecords
{
public void SaveDBRecords(TreeNode node)
{
// create dataset connections here
String parentID = Guid.NewGuid().ToString();
String nodeText = node.Text;
int nodeLevel = node.Level;
// store information to db here
foreach (TreeNode childNode in node.Nodes)
{
SaveDBRecords(childNode);
}
}
}
My class is longer than that, but I just want to keep this simple
since I am confused already.
This is what my sample tree look like until I can get this thing
working.
for (int x = 0; x < 2; ++x)
{
TreeNode ParentNode = tvMain.Nodes.Add("Parent" +
x.ToString());
TreeNode ChildNode = ParentNode.Nodes.Add("Child" +
x.ToString());
TreeNode SubChildNode = ChildNode.Nodes.Add("SubChild"
+ x.ToString());
TreeNode SubSubChildNode =
SubChildNode.Nodes.Add("SubSubChild" + x.ToString());
}
Once I can get the storing of the information to the DB, then I can
worry about loading it back
in. But thats another headache I am not eady to tackle just yet.
Thanks
John
This is what i am using to store my treeview layout into a db, I
am only using a few fields to make it easier to understand while
I am attempting to restore it back into the tree.
Text "Parent0", Level 0
Text "Child0", Level 1
Text "SubChild0", Level 2
Now I have read many posts where others are saying to store a unique
id
of the parent. I am having a bit of trouble trying to store an id
somewhere
and retrieve it on the next loop.
This is what I am looking at in the debugger, I am looking for
something that
I can use that is unique. This is a multilayer, many roots and many
nested nodes
in the treeview. This is just a sample I am posting.
//-------------------- Debugger values ------------------------------
+ Parent null System.Windows.Forms.TreeNode
Text "Parent0" string
Level 0 int
+ FirstNode {Text = "Child0"} System.Windows.Forms.TreeNode
+ NextNode {Text = "Parent1"} System.Windows.Forms.TreeNode
+ NextVisibleNode {Text = "Child0"} System.Windows.Forms.TreeNode
+ Parent {Text = "Parent0"} System.Windows.Forms.TreeNode
Text "Child0" string
Level 1 int
+ FirstNode {Text = "SubChild0"} System.Windows.Forms.TreeNode
+ NextNode null System.Windows.Forms.TreeNode
+ NextVisibleNode {Text = "SubChild0"} System.Windows.Forms.TreeNode
+ Parent {Text = "Child0"} System.Windows.Forms.TreeNode
Text "SubChild0" string
Level 2 int
+ FirstNode {Text = "SubSubChild0"} System.Windows.Forms.TreeNode
+ NextNode null System.Windows.Forms.TreeNode
+ NextVisibleNode {Text = "SubSubChild0"}
System.Windows.Forms.TreeNode
//-------------------- Debugger values ------------------------------
Lets say I start the loop, my first node will be "Parent0" it does not
have a parent, its a
rootnode, the ParentID for this will be NULL. On th next round I come
up with "Child0"
and that node has a parent which is "Parent0". Now how would I
generate a GUID for
Parent0, and tell Child0 who its parent is? Even if I create an
instance of my struct and store
the information in the struct. That information will be lost on my
next round of the loop because
I have to create a new instance of the struct again.
I am pretty confused right now, maybe I am over analyzing everything
and thats why i cant
get anything to work. Here is some sample code that leads to nowhere.
SaveTreeViewRecords SaveRecords = new
SaveTreeViewRecords();
foreach (TreeNode node in TreeView1.Nodes)
{
SaveRecords.SaveDBRecords(node);
}
class SaveTreeViewRecords
{
public void SaveDBRecords(TreeNode node)
{
// create dataset connections here
String parentID = Guid.NewGuid().ToString();
String nodeText = node.Text;
int nodeLevel = node.Level;
// store information to db here
foreach (TreeNode childNode in node.Nodes)
{
SaveDBRecords(childNode);
}
}
}
My class is longer than that, but I just want to keep this simple
since I am confused already.
This is what my sample tree look like until I can get this thing
working.
for (int x = 0; x < 2; ++x)
{
TreeNode ParentNode = tvMain.Nodes.Add("Parent" +
x.ToString());
TreeNode ChildNode = ParentNode.Nodes.Add("Child" +
x.ToString());
TreeNode SubChildNode = ChildNode.Nodes.Add("SubChild"
+ x.ToString());
TreeNode SubSubChildNode =
SubChildNode.Nodes.Add("SubSubChild" + x.ToString());
}
Once I can get the storing of the information to the DB, then I can
worry about loading it back
in. But thats another headache I am not eady to tackle just yet.
Thanks
John