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
For some reason the nodes are not being update to the treeview, the nodes are not showing
foreach (var gRow in Group)
{ if (!ultraTree1.Nodes.Exists(gRow .PARENT.ToString()))
{ UltraTreeNode GetUltraTreeNode = new UltraTreeNode(gRow .PARENT.ToString());
if (!this.ultraTree1.Nodes.Exists(GetUltraTreeNode.Key))
{ this.ultraTree1.Nodes.Add(GetUltraTreeNode.Key); }
}
Ok I am not for sure, why the tree is not showing the nodes, I have add the nodes usinfg the logic below.
foreach
(var gRowin Group){
if (!ultraTree1.Nodes.Exists(gRowin .PARENT.ToString()))
{
UltraTreeNode GetUltraTreeNode = new UltraTreeNode(gRowin .PARENT.ToString());
this.ultraTree1.Nodes.Add(GetUltraTreeNode.Key);
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.
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 } } }