下面的代码用于在用户控件中加载树视图的 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);
}