简体   繁体   English

在Treeview C#Winforms中添加新文件夹

[英]Adding New folder in treeview c# Winforms

I am using Treeview in C# winforms to list all existing images in directory, i also created button event to add New Folder, but now problem is when i add new node its created but in actual no any folder created on actual drive/directory, so please help me out. 我在C#winforms中使用Treeview列出目录中的所有现有图像,我还创建了按钮事件以添加“新文件夹”,但是现在的问题是当我添加其创建的新节点但实际上在实际驱动器/目录上未创建任何文件夹时,所以请帮帮我。 Here is my Code.. 这是我的代码。

private void btnAddFolder_Click(object sender, EventArgs e)
{
var newNode = treeView1.SelectedNode.Nodes.Add("New Folder");
newNode.BeginEdit();
}

You don't have any code for creating directories there - just for adding the node to your tree. 您没有在此处创建目录的任何代码-仅用于将节点添加到树中。

I am assuming you have some kind of path information on each node (perhaps in the 'Tag' data). 我假设您在每个节点上都有某种路径信息(也许在“标签”数据中)。 If that's the case, you need to combine this data with a call to CreateDirectory, as follows: 在这种情况下,您需要将此数据与对CreateDirectory的调用结合起来,如下所示:

Directory.CreateDirectory(Path.Combine(treeView1.SelectedNode.Tag as string, "New Folder"));

This will create a directory which is represented by the combination of the path of the current node and the string 'New Folder'. 这将创建一个目录,该目录由当前节点的路径和字符串“ New Folder”的组合表示。

The TreeNode.Tag property is described here . 这里描述TreeNode.Tag属性。

The Directory.CreateDirectory method is described here . Directory.CreateDirectory方法在此处描述。

The Path.Combine method is described here here . 这里描述Path.Combine方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM