From what I understand, the UltraTree control will automatically generate all levels depending on the relations you specify between two tables.
I'm creating a proof-of-concept using folders. One table has all the folders. The second table has the folder parent-child relationships. All the folders are displayed in the tree, but only two levels deep. See the picture attached. For example, you can see how 5 should be under 4, and 7 under 5, but 4 and 5 are showing up at the root level.
Also note that it only shows the ID instead of the Name (A, B, C). Is there a way to get it to show the Name?
Here is the code to generate data in the dataset tables.
var folders = this.dataSet1.Tables["Folders"];
folders.Rows.Add(0, "Attachments"); folders.Rows.Add(1, "A"); folders.Rows.Add(2, "B"); folders.Rows.Add(3, "C"); folders.Rows.Add(4, "D"); folders.Rows.Add(5, "E"); folders.Rows.Add(6, "F"); folders.Rows.Add(7, "G"); folders.Rows.Add(8, "H"); folders.Rows.Add(9, "I");
var folderHier = this.dataSet1.Tables["FolderHier"];
folderHier.Rows.Add(1, 0); folderHier.Rows.Add(2, 0); folderHier.Rows.Add(3, 0); folderHier.Rows.Add(4, 1); folderHier.Rows.Add(5, 4); folderHier.Rows.Add(6, 2); folderHier.Rows.Add(7, 5); folderHier.Rows.Add(8, 3); folderHier.Rows.Add(9, 3);
DataRelation dr = new DataRelation("FolderHierarchy", dataSet1.Tables["Folders"].Columns["FolderID"], dataSet1.Tables["FolderHier"].Columns["FolderID"]); dataSet1.Relations.Add(dr);
ultraTree1.DataSource = this.dataSet1; ultraTree1.DataMember = "Folders";
Hello Sam,
I'm glad I was, able to help,
Thank you for choosing Infragistics!
RegardsIvan Kitanov
That did it, thank you!
When the UltraTree is bound to a data source, the value of the node's Text property is determined by the data source. Be default, the cell from the first column in the column set is used; if you want to change this, you can handle the ColumnSetGenerated event, and assign a different column to the e.ColumnSet.NodeTextColumn property. It could be achieved with the following code:
private void UltraTree1_ColumnSetGenerated(object sender, Infragistics.Win.UltraWinTree.ColumnSetGeneratedEventArgs e) { e.ColumnSet.NodeTextColumn = e.ColumnSet.Columns["Name"]; }
Please let me know if you need any further assistance.
Regards, Ivan Kitanov
I got it to work by using sample code that was posted on the forum.
The only issue now is that only the ID shows up as the node name, instead of the Name field value. Is there a way to define which field to display as the node text?
private void LoadData() { DataSet ds = new DataSet();
DataTable folders = new DataTable("Folders"); folders.Columns.Add("ID", typeof(int)); folders.Columns.Add("Name", typeof(string)); folders.Columns.Add("PID", typeof(int));
folders.Rows.Add(0, "Root", null); folders.Rows.Add(1, "A", 0); folders.Rows.Add(2, "B", 0); folders.Rows.Add(3, "C", 2); folders.Rows.Add(4, "D", 3); folders.Rows.Add(5, "E", 1); folders.Rows.Add(6, "F", 5); folders.Rows.Add(7, "G", 6); folders.Rows.Add(8, "H", 0); folders.Rows.Add(9, "I", 0);
ds.Tables.Add(folders);
DataRelation dr = new DataRelation("RR", folders.Columns["ID"], folders.Columns["PID"]) { Nested = true };
ds.Relations.Add(dr);
ultraTree1.DataSource = folders; }
private void ultraTree1_InitializeDataNode(object sender, Infragistics.Win.UltraWinTree.InitializeDataNodeEventArgs e) { if (e.Node.IsRootLevelNode && !(e.Node.Cells["PID"].Value is System.DBNull)) { e.Node.Visible = false; } else { e.Node.Visible = true; } }