The below code works to load xml files of a tree view in the user-control. Somehow i feel the code for expand/close is not well coded. Is there any other way of coding this in a more clean form?
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);
}
Call it like this: