Kind of hard to explain, but I have a tree and tree represents tables in a relational database, basically the Dictionary.
Well if you click the parent node, it builds the children and grandchildren. So now let's say I select TABLE1 as the parent node, I wil get a Child node called DEPENDS ON, this will drill down to other "parent" names, let's say TABLE2. Now if I select TABLE2, it basically acts like if it was a Parent and the same process repeats where I get another Child called DEPENDS ON. Now this already works in C# controls.
Now for my problem trying to duplicate this with the UltraWinTree. Only one ACTIVENODE can be enabled at a time, so when I click on TABLE2 in my example above, I get an error since I already have the ACTIVENODE of the first Parent.
I attached the code where I get the error when I click on the TABLE2 scenario, this always works the first time since I get my first ACTIVENODE which is the first Parent selected.
I get the error message that the Key already exist: Depends on
if (oNode.GetNodeCount(false) < 1) { //////////////////////////////////////////////// /// Get Depends On only if it is a file //////////////////////////////////////////////// if (ParentIsFile && IsFile) // we add the dependants and the depends on { //////////////////////////////////////////////// /// Get Depends On //////////////////////////////////////////////// UltraTreeNode oDependsOn = new UltraTreeNode("Depends On"); //This is the code change to using the UltraTree control
//This is where I get the error message that the Key already exist: Depends on this.ultraTree1.ActiveNode.Nodes.Add(oDependsOn);
//Old code from Native Tree control //this.ultraTree1.SelectedNodes.Nodes.Add(oDependsOn); foreach (DataRow dr_GetTableDefSql in dt_GetTableDefSql.Rows) { string temp = dr_GetTableDefSql["ColumnName"].ToString(); if (temp.ToLower().EndsWith("id")) { string strRelative = temp.Trim().Substring(0, temp.Trim().Length - 2); if (strRelative.ToLower() == "user") strRelative = "SyStaff"; dv_SyDictTables.RowFilter = "Tablename = '" + strRelative.Trim() + "'"; if (dv_SyDictTables.Count > 0) { if (strRelative != TableName) { UltraTreeNode oChild = new UltraTreeNode(); oChild = new UltraTreeNode(strRelative); oDependsOn.Nodes.Add(oChild); } } } }
I was getting same error 'key already exists:...' and the solution 'use the overload of the Nodes collection;s Add method that takes a key and the text' worked for me.
Thank you!
You are making the assumption that the node that was found is in the root-level collection of the tree.
Keys in the tree have to be unique to the entire tree, not just to the collection they are in. GetNodeBYKey will find a node anywhere in the entire tree. So your node is probably the child node of some other node and does not exist in the tree.Nodes collection.
You need to remove the node from the nodes collection it is in. Since you don't seem to care where the node is in the tree, the easiest thing to do is this:
node1.Remove();
Dim node1 As UltraTreeNode = treeControl.GetNodeByKey(key)
If Not node1 Is Nothing Then
treeControl.Nodes.Remove(node1)
End If
I get an exception "The node cannot be removed because it does not belong to this collection."
GetNodeByKey() returns a valid node, so any reason why the exception?
I have a similar problem.
I add a node to the tree treeControl.Nodes.Add(key,Name)
I then remove the node treeControl.Nodes.Item(key).remove
I then try to add the node to the tree again, and I get an exception key already exist
What am I doing wrong here?
felix_Serra said:I have the same application working but with native controls