I have a TreeView in WinForm application, and I am using the add, reorder and delete methods to add new nodes, reorder existing nodes and delete old notes.
Sometimes when I add a new item it does net show immediately in the TreeView, but it does show correctly when I add the next node. It seems to happen randomly, so it’s difficult to find the root cause.
Even when the node does not show correctly in the UI, the node count is correct.
TreeView1.BeginUpdate();
TreeView1.Nodes.Add("P1", "Parent");
foreach(User u in items)
{
if( condition)
{
node.Text =u.sNodeText;
node.Tag = u;
node.Text = u.sNodeText;
GetChildren(node);
TreeView1.Nodes["P1"].Nodes.Add((TreeNode)node.Clone());
}
}
TreeView1.ExpandAll();
TreeView1.EndUpdate();
TreeView1.Refresh();
Can anyone answer this question? I think the question is not meaningless.
Here is the GetChildren method.
private void GetChildren(TreeNode node)
{
TreeNode Node = null;
User nodeCat = (User)node.Tag;
foreach (User cat in items)
{
if (cat.sParentID == nodeCat.sID)
{
Node = node.Nodes.Add(cat.sNodeText);
Node.Tag = cat;
GetChildren(Node);
}
}
Have you tried
Invalidate()versusRefresh()? Refresh only redraws the Client area, while Invalidate redraws the entire control. It’s just a shot in the dark… I’ve never encountered this problem before.