【发布时间】:2012-05-23 17:01:17
【问题描述】:
我进行了一些研究,发现了一些与我的问题相近的主题,但没有一个能解决它。
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 item in contents)循环中,将第二个if更改为嵌套在第一个if中。如果路径为空白,您不希望第二个if运行。因为那样你最终只是再次为源中继调用GetList(IE:"https://sourcecode/svn/XXXXXX" + path变为https://sourcecode/svn/XXXXXX,如果path是一个空字符串)。 -
没错,它并没有解决我的问题,但我会改变它。