Stackflow和C#newbie在这里!
我在下面有一些代码将一个字符串列表加载到树视图控件中,它运行良好.唯一的问题是速度.当列表很大时,加载需要时间,这不是问题,除了它会暂停UI一段时间.
所以一个例子就是像这样的字符串列表(但更大):
c:\ drivers\test1.txt
c:\ drivers\test2.txt
c:\ drivers\folder\test1.txt
c:\ brother\tester\text1.zip
c:\ brother\another\text2.zip
c:\ data\company1\accounts.rar
c:\ data\company2\accounts.rar
treeview使用反斜杠标记分割字符串,并将它们整齐地放在资源管理器视图中 - 这很好!
tvRestore是示例中的Treeview控件.
foreach (string path in lstKeys)
{
lastNode = null;
subPathAgg = string.Empty;
foreach (string subPath in path.Split(new string[] { "\\" }, StringSplitOptions.None))
{
foreach (string item in subPath.Split(new string[] { "\\" }, StringSplitOptions.None))
{
if (item == "" || item == null)
{
continue;
}
subPathAgg += item + "\\";
TreeNode[] n = tvRestore.Nodes.Find(subPathAgg, true);
if (n.Length > 0) …
Run Code Online (Sandbox Code Playgroud)