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 didn't follow exactly what you are trying to do here, but the reason for the exception is that when you create the 'DependsOn' node, you are using the constructor that takes the node's key, and all keys must be unique, so the control throws the duplicate key exception. You can avoid this by using the constructor overload that takes the key and the text, and specify null for the key.
Yeah, this was hard to explain. I have the same application working but with native controls.
So in this screen shot, the SyStudent is the Parent Node and when you click on it, if it have tables that it depends on, then you get another node to show more tables. (AMTITLE)
You can keep clicking on the tables under the Depends On and this process repeats. I basically took the same code and just trying to duplicate it with Infragistics controls. I debugged the same code and I don't get that error and just frustrated on how to circumvent using Infragistics controls.
felix_Serra said:I have the same application working but with native controls
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!