Hi Victor,
Thank you for your post.
From your message, I understand that you want to:
1) Save the selection of the TreeView to database
2) Load the selection of the TreeView from database later
I think how you achieve this largely depends on how you can uniquely
identify each node in the TreeView. If each node has unique Value, then you
can use TreeNode.ValuePath property as the key to save selected nodes. If
the nodes may have identical Value but the nodes count and order will not
change, then you can use the index of each node in its parent's ChildNodes
collection as the key to save selected nodes.
Either way, you need to recursively walk the TreeView's Nodes collection to
get/set the selection:
SaveTree(TreeView1.Nodes);
private void SaveTree(TreeNodeCollection tnc)
{
foreach(TreeNode node in tnc)
{
if (node.Checked)
{
...
}
SaveTree(node.ChildNodes);
}
}
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.