且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中的Combobox中添加文件夹浏览器?

更新时间:2023-09-25 19:08:58

该下拉列表正在打开treview节点文件。首先,你必须制作一个treeview组合框。

然后你将绑定系统目录列表。

我们提供一些部分解决方案,让你在你身边找到一个好的解决方案

带树视图的第一个组合框

http:// www。 brad-smith.info/blog/archives/193 [ ^ ]

http:/ /demos.telerik.com/aspnet-ajax/treeview/examples/functionality/treeviewcombobox/defaultcs.aspx [ ^ ]





获取要在此组合框上绑定的系统目录

That dropdown is opening a treview node file. For this first you have to make one treeview combobox.
Then you will bind system direcotory list.
We are providing some part solution to make you a good solution from your side
First combobox with treeview
http://www.brad-smith.info/blog/archives/193[^]
http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/treeviewcombobox/defaultcs.aspx[^]


Get the system directory to bind on this combobox
void ListDirectory()
{
    treeView1.Nodes.Clear();
    var rootDirectoryInfo = new DirectoryInfo(txtPath.Text);
    treeView1.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo));
    LoadFileDetails("");
}
TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)
{
    var directoryNode = new TreeNode(directoryInfo.Name);
    try
    {
        foreach (var directory in directoryInfo.GetDirectories())
        {
            directoryNode.Nodes.Add(CreateDirectoryNode(directory)); 
        } 
    }
    catch (UnauthorizedAccessException) { }
    catch (Exception) { }
    return directoryNode;
}