I have a TreeView application in WinForm, and I use the add , reorder and delete methods to add new nodes, reorder existing nodes, and delete old notes.
Sometimes, when I add a new element, it shows net show directly in the TreeView , but it correctly shows when I add the next node. It seems to be happening by chance, so it's hard to find the root cause.
Even if the node does not display correctly in the user interface, the node counter 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 this question does not make sense. 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); } }
source share