I have the following code to delete a company displayed in my ASP.NET 2.0 Tree control:
protected void Delete_Click(object sender, EventArgs e)
{
TreeNode parentNode = null;
int expandDepth = 1;
string companyID = "";
expandDepth = companyTree.SelectedNode.Depth;
if(companyTree.SelectedNode.Parent != null)
parentNode = companyTree.SelectedNode.Parent;
companyID = companyTree.SelectedNode.Value;
// Delete the company...
//// Companies.DeleteCompany(new Guid(companyID));
// Repopulate the tree...
DataTable dtTree = Companies.GetTree();
companyTree.Nodes.Clear();
companyTree.Nodes.Add(Tree.BuildTree(dtTree, Page));
companyTree.ExpandDepth = expandDepth;
companyTree.ShowLines = true;
if (parentNode != null)
{
List<TreeNode> parentChain = new List<TreeNode>(expandDepth + 1);
parentChain.Add(parentNode);
while (parentNode.Parent != null)
{
parentChain.Add(parentNode.Parent);
parentNode = parentNode.Parent;
}
for (int i = parentChain.Count - 1; i >= 0; i--)
{
parentChain[i].Expand();
}
parentChain[0].Select();
}
}
For some reason, the tree displays as completely collapsed (root node only showing) and nothing I do seems to make it expand back to at least the parent of the node I deleted. Any suggestions?