且构网

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

如何使用C#在树视图控件中选择内部节点

更新时间:2023-11-04 23:43:46

你明白通过将驱动器名称放在TreeView中,这就是你所拥有的。您必须提供用于在驱动器节点下添加目录节点的代码。



我强烈建议你一次只下降一个级别。例如,仅在所选驱动器下方添加目录节点。如果选择了其中一个目录,则只展开节点以包含所选目录的子目录。否则用户将面临漫长的等待时间。



此外,还有一个控件可以执行您想要的操作。它被称为文件夹浏览器对话框 [ ^ ]。

I am having a tree view control.

I have given all drives as nodes.

If I select a drive it should select all the folders and its subfolders.

How to do this. I use Checkbox to select these drives

You do understand that by placing the drive names in a TreeView, that's all you have. You must supply code that adds the directory nodes beneath the drive nodes.

I strongly suggest that you only descend one level at a time. For example only add directory nodes immediately beneath a selected drive. If one of those directories is selected, only expand the nodes to include the the selected directory's subdirectories. Otherwise the user will be faced with long wait times.

Also, there is a control to do what you appear to want. It's called Folder Browser Dialog[^].