Make folders nodes in TreeView, and move nodes between them
I want to make a treeview structure开发者_运维百科 like this. I can only find an example on how to copy nodes.
But I don't know how to organize it to folders, to move nodes between them. Any advice will be very helpful.
I'm using winforms
.
Basically you are going to have a recursive loop like so:
protected void Populate(TreeNode parentNode, DirectoryInfo directory)
{
foreach (DirectoryInfo dir in directory.GetDirectories())
{
TreeNode node = parentNode.Nodes[dir.Name]
?? parentNode.Nodes.Add(dir.Name, dir.Name);
node.Tag = dir;
// node.ContextMenuStrip = cmenu;
Populate(node, dir);
}
}
To drag and drop with TreeView, see this Microsoft example.
精彩评论