It's probably a bug, I think you should report this to the
MSDN Feedback Center.
It will work if you clear all the nodes in the TreeView control after you have moved the node, and then create a new node where you add all your ParentNode childs into the new parent node, and then add the parent node to the TreeView
The following code is the workaround:
protected void Button1_Click(object sender, EventArgs e)
{
TreeNode CurNode = TreeView1.SelectedNode;
TreeNode ParentNode;
if (CurNode != null && CurNode.Depth != 0)
{
int idx;
ParentNode = CurNode.Parent;
idx = ParentNode.ChildNodes.IndexOf(CurNode);
if (idx > 0)
{
ParentNode.ChildNodes.AddAt(idx - 1, CurNode);
ParentNode.ChildNodes.RemoveAt(idx+1);
}
//Workaround
TreeView1.Nodes.Clear();
TreeNode root = new TreeNode(ParentNode.Text);
root.Expand();
foreach( TreeNode child in ParentNode.ChildNodes)
{
root.ChildNodes.Add(child);
}
TreeView1.Nodes.Add(root);
//Workaround
}
}
/Fredrik Norm?n NSQUARED2
Microsoft MVP, MCSD, MCAD, MCT
CornerstoneMy Blog, ASP.Net 2.0 etc