[英]Expand/Close user-control tree
以下代码用于在用户控件中加载树视图的xml文件。 不知何故,我觉得扩展/关闭的代码编码不正确。 还有其他以更简洁的形式进行编码的方式吗?
try{
this.tvTraceSelect.Progress = true;
this.tvTraceSelect.UnitsPath = unitsPath;
this.tvTraceSelect.TracesPath = tracesPath;
this.tvTraceSelect.View = Traces.View.Files;
this.tvTraceSelect.TreeView.CollapseAll();
if (this.tvTraceSelect.TreeView.Nodes.Count > 0)
{
this.tvTraceSelect.TreeView.Nodes[0].Expand();
if (this.tvTraceSelect.TreeView.Nodes[0].Nodes.Count > 0)
{
this.tvTraceSelect.TreeView.Nodes[0].Nodes[0].Expand();
if (this.tvTraceSelect.TreeView.Nodes[0].Nodes[0].Nodes.Count > 0)
{
this.tvTraceSelect.TreeView.Nodes[0].Nodes[0].Nodes[0].Expand();
if (this.tvTraceSelect.TreeView.Nodes[0].Nodes[0].Nodes[0].Nodes.Count > 0)
{
this.tvTraceSelect.TreeView.Nodes[0].Nodes[0].Nodes[0].Nodes[0].Expand();
}
}
}
}
}catch (Exception _excep)
{
MessageBox.Show(this, "An error occured during the initialization of the InitTracesView .\nDetails: "
+ _excep.Message + "\n\n" + _excep.StackTrace, "Initialization error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
public void ExpandFirst(TreeNodeCollection nodes)
{
if (nodes.Count > 0)
{
nodes[0].Expand();
ExpandFirst(nodes[0].Nodes);
}
}
这样称呼它:
ExpandFirst(this.tvTraceSelect.TreeView.Nodes)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.