我做了一些研究,我发现一些话题接近我的问题,但他们都没有解决它。从C列表填充treeview#
populate treeview from a list of path
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx
http://social.msdn.microsoft.com/Forums/en/winforms/thread/dae1c72a-dd28-4232-9aa4-5b38705c0a97
SharpSvn: Getting repository structure and individual files
我想打一个库浏览器为我的SVN文件夹,以便用户可以选择一个文件夹,它会回归到一个文本框。
这是我的实际代码:
private void sourceTrunkBrowseButton_Click(object sender, EventArgs e)
{
using (SvnClient svnClient = new SvnClient())
{
Collection<SvnListEventArgs> contents;
Collection<SvnListEventArgs> contents2;
List<TreeItem> files = new List<TreeItem>();
if (svnClient.GetList(new Uri("https://sourcecode/svn/XXXXXX"), out contents))
{
foreach (SvnListEventArgs item in contents)
{
if (item.Path != "")
{
files.Add(new TreeItem(item.Path, 0));
if (svnClient.GetList(new Uri("https://sourcecode/svn/XXXXX" + item.Path), out contents2) && item.Path != "")
{
foreach (SvnListEventArgs item2 in contents2)
{
if (item2.Path != "")
{
files.Add(new TreeItem(item2.Path, 1));
}
}
}
}
}
}
svnBrowser_.FillMyTreeView(files);
svnBrowser_.Show();
}
}
而且
public void FillMyTreeView(List<AutoTrunk.TreeItem> files)
{
// Suppress repainting the TreeView until all the objects have been created.
svnTreeView.BeginUpdate();
svnTreeView.Nodes.Clear();
List<TreeNode> roots = new List<TreeNode>();
roots.Add(svnTreeView.Nodes.Add("Items"));
foreach (AutoTrunk.TreeItem item in files)
{
if (item.Level == roots.Count) roots.Add(roots[roots.Count - 1].LastNode);
roots[item.Level].Nodes.Add(item.BrowsePath);
}
// Begin repainting the TreeView.
svnTreeView.EndUpdate();
}
但是我的树看起来就像这样:
+---Name1
| |
| +------Name2
| |
| +------Name3
| |
| +------Name5
| |
| +------Name6
|
+---Name4
但名称5名6应该是在名称4
对不起为长的职位,并感谢!
在您的第一个'foreach(内容中的SvnListEventArgs项)'循环中,将第二个'if'更改为嵌套在第一个'if'中。如果路径为空白,您不希望第二个“if”运行。因为那么你最终只会再次为源主干调用'GetList'(IE:'“https:// sourcecode/svn/XXXXXX”+ path'将变成'https:// sourcecode/svn/XXXXXX' if if'path'是一个空字符串)。 – SPFiredrake
没错,它不能解决我的问题,但我会改变它。 – LolCat