Hi,
I'd like to display a hierarchy of the following structure in an unbound (=code-drawn) UltraTree.
So, this could look that way:
I've built two columnsets, colsetDatepart and colsetRequirement, but the UltraTree view style strikes back:
What can I do? Any hint appreciated.
Thanks
Martin
Hello Martin,
Two different column sets could be used for sibling notes, however instead of overriding the column set of the child collection of the parent node, what you would need to do is overriding the columnSet property of the node itself. It could be done with the following code:
childNode.Override.ColumnSet = columnSet1;
This code would affect only the node and not its siblings so each sibling can have a different column set. For example, the Year node can have Half year child node with colsetDatepart, while the YearRequirement nodes can have the colsetRequirement.
Below I am pasting a code snippet that demonstrates what I have explained above, it demonstrates how parent node can have child nodes with different column sets, the code covers only 2 level hierarchy, however the logic for all the other levels is exactly the same to the logic used with 2 level hierarchy.
this.ultraTree1.ViewStyle = ViewStyle.FreeForm; UltraTreeNode parentNode1 = this.ultraTree1.Nodes.Add("Year"); UltraTreeColumnSet columnSet1 = new UltraTreeColumnSet(); columnSet1.Columns.Add("Name"); columnSet1.Columns.Add("A"); columnSet1.Columns.Add("B"); columnSet1.Columns.Add("C"); UltraTreeColumnSet columnSet2 = new UltraTreeColumnSet(); columnSet2.Columns.Add("Name"); columnSet2.Columns.Add("1"); columnSet2.Columns.Add("2"); UltraTreeNode childNode = parentNode1.Nodes.Add(); childNode.Override.ColumnSet = columnSet2; childNode.Cells["Name"].Value = "Half Year"; childNode.Cells["1"].Value = "11"; childNode.Cells["2"].Value = "21"; childNode.Cells["Name"].Column.AutoSizeMode = ColumnAutoSizeMode.AllNodes; childNode = parentNode1.Nodes.Add(); childNode.Override.ColumnSet = columnSet1; childNode.Cells["Name"].Value = "YearRequirement1"; childNode.Cells["A"].Value = "A1"; childNode.Cells["B"].Value = "B1"; childNode.Cells["C"].Value = "C1"; childNode.Cells["Name"].Column.AutoSizeMode = ColumnAutoSizeMode.AllNodes; childNode = parentNode1.Nodes.Add(); childNode.Override.ColumnSet = columnSet1; childNode.Cells["Name"].Value = "YearRequirement2"; childNode.Cells["A"].Value = "A2"; childNode.Cells["B"].Value = "B2"; childNode.Cells["C"].Value = "C2"; childNode.Cells["Name"].Column.AutoSizeMode = ColumnAutoSizeMode.AllNodes; this.ultraTree1.ExpandAll();
I am also attaching a screenshot that demonstrates how would the tree look, when there are sibling nodes with different column sets.
Please let me know if you have any questions.
Regards, Ivan Kitanov
Hello Ivan,
thanks for your answer. That's been my approach as well... But the issue with that approach is that the requirement nodes of "Year" each have a caption. Is there a way to show captions only once per block of consecutive child nodes of the same columnset?
I've edited your screenshot below to be clearer:
Regards
Thank you for the clarification. To do this you would need to set the column set of the child nodes of the parent to the colsetRequirement and then afterwards you would need to override the columns set only on those nodes that would be from the colsetDatepart. The code for this should be similar to the code below:
this.ultraTree1.ViewStyle = ViewStyle.FreeForm; UltraTreeNode parentNode1 = this.ultraTree1.Nodes.Add("Year"); UltraTreeColumnSet columnSet1 = new UltraTreeColumnSet(); columnSet1.Columns.Add("Name"); columnSet1.Columns.Add("A"); columnSet1.Columns.Add("B"); columnSet1.Columns.Add("C"); UltraTreeColumnSet columnSet2 = new UltraTreeColumnSet(); columnSet2.Columns.Add("Name"); columnSet2.Columns.Add("1"); columnSet2.Columns.Add("2"); parentNode1.Nodes.Override.ColumnSet = columnSet1; UltraTreeNode childNode = parentNode1.Nodes.Add(); childNode.Override.ColumnSet = columnSet2; childNode.Cells["Name"].Value = "Half Year"; childNode.Cells["1"].Value = "11"; childNode.Cells["2"].Value = "21"; childNode.Cells["Name"].Column.AutoSizeMode = ColumnAutoSizeMode.AllNodes; childNode = parentNode1.Nodes.Add(); childNode.Cells["Name"].Value = "YearRequirement1"; childNode.Cells["A"].Value = "A1"; childNode.Cells["B"].Value = "B1"; childNode.Cells["C"].Value = "C1"; childNode.Cells["Name"].Column.AutoSizeMode = ColumnAutoSizeMode.AllNodes; childNode = parentNode1.Nodes.Add(); childNode.Cells["Name"].Value = "YearRequirement2"; childNode.Cells["A"].Value = "A2"; childNode.Cells["B"].Value = "B2"; childNode.Cells["C"].Value = "C2"; childNode.Cells["Name"].Column.AutoSizeMode = ColumnAutoSizeMode.AllNodes; this.ultraTree1.ExpandAll();
I am also attaching a screenshot that demonstrates how would the tree look like after the change
Hi Ivan,
thank you, this works indeed, at least in the demo .
In the real world, I struggle to find the place where to change the node.Nodes.Override.Columnset, as my data come from two datatables. I've included a small runnable example which uses the sample data via datatables. Where would you edit the code?
MartinsDemo.zip
Thank you!
I have modified your sample in order to display the colsetRequirement with a single header. The changes that I have done are the following:
In the foreach of the DateParts I have added the following line, which sets each of their child nodes to have the colsetRequirement column set:
nde.Nodes.Override.ColumnSet = colsetRequirement;
Since the colsetDatePart node would have its set overriden to colsetDatePart this would not apply to them. Additionally, I have also changed the foreach that creates the requirement nodes to first create the node and add it to the tree and then modify the cell values of the node. If the node has its cell values assigned first it would result in NullReferenceException so creating and adding the node prevents this. The code that has been changed can be found below:
//Draw Requirements foreach (var rowRequirement in _dstDemo.Requirements) { //Build node var nde = new UltraTreeNode(key: rowRequirement.Name); // {Override = {ColumnSet = colsetRequirement}}; // get node parent var ndeParent = ultraTree1.GetNodeByKey(rowRequirement.DatePart); //Insert node hierarchically. Requirements are always children of a Datepart node. ndeParent.Nodes.Add(nde); // add the values to each cell moved after the node has been already created and addded to the tree foreach (var column in colsetRequirement.Columns) { nde.SetCellValue(column, rowRequirement[column.Key]); //colset columns and datarow columns match 1:1! } }
Additionally, I am attaching the modified version of the sample as well as a screenshot with the resulting tree. Please test the sample on your side and let me know if you have any questions.
MartinsDemo_Modified.zip
that's exactly what I needed. Thank you so much, you made my day.
Kind regards
Hi Martin,
I'm glad I was able to help.
Thank you for choosing Infragistics!
Regards,Ivan Kitanov