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
Hi Martin,
I'm glad I was able to help.
Thank you for choosing Infragistics!
Regards,Ivan Kitanov
Hi Ivan,
that's exactly what I needed. Thank you so much, you made my day.
Kind regards
Hello Martin,
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.
Regards, Ivan Kitanov
MartinsDemo_Modified.zip
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!
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
Please let me know if you have any questions.