Can someone send me a small example with 3 parents levels that has 3 child to each parent. First time using a treeview. I want to build the tree dynamically in code. This is would be helpful.
parent A
child A.1
child A.2
child. A.3
parent B
child B.1
child B.2
child. B.3
child C.1
child C.2
child. C.3
foreach( var gRow in Group) { if (!ultraTree1.Nodes.Contains(gRow.PARENT)) { UltraTreeNode GetUltraTreeNode = new UltraTreeNode(bLine.gRow.ToString(), bLine.INDENT.ToString()); if (!this.ultraTree1.Nodes.Contains(GetUltraTreeNode.Key)) { this.ultraTree1.Nodes.Add(GetUltraTreeNode); //I keep getting key already exist. I am not understanding why if I have logic thats said not exist } } }
KeithDudley said:I keep getting key already exist. I am not understanding why if I have logic thats said not exist
For one thing, the Contains method doesn't take a key, it takes in a node object. So it will always return false if you pass in a string.You should be using the Exists method if you want to check for the existance of a key.
Also, node keys have to be unique to the entire tree, not just unique to the collection they are in. So even if the Exists method returns false, that only means that a node with that key does not exist in that collection. It does not account for every nodes collection in the entire tree.