Hello!
I searched the forum but didnt really find an answer, hope u can help me:
I have a DataSet like this:
Region Name
North Smith
North Bond
North Simpson
South Willis
Now i want this displayed in a UltraTree like this:
-North
-Smith
-Bond
- Simpson
-South
- Willis
I do
ultraTree1.DataSource = myDataTable;
but then i get a tree like
I tried other things too, but didnt get the tree like i want it.
You have to create a DataRelation and add it to the DataSet's Relations collection. Once the DataSet is properly structured, you can use the control's SetDataBinding method to assign that DataSet to the DataSource property, and the name of the table that contains the regions to the DataMember property.
NavigationNode ParentID
A NULL
B NULL
C A
D B
E D
-A
-C
-B
- D
- E
Hi,
The tree in this case is accurately reflecting the structure of your data source. All of the rows exist in the root-level table and then the relationship creates the child nodes.
So what you can do in a case like this is simply hide the root-level nodes that are children. A good place to do this is in the tree's InitializeDataNode event. If you installed the samples with NetAdvantage, there's a sample called "DataBinding (Recursive)" that demonstrates this technique. But basically, the event fires for each node and you examine the node to see if it's a root node and then examine the ParentId. If the node is at the root level (has no parent node) and has a ParentId, then you hide the node.
Here's the code from the sample which uses SupervisorID as the parent ID, but you get the idea.
// Make sure that only the highest-level employees show up at // the root level of the tree. if (e.Node.Parent == null && e.Node.Cells["SupervisorID"].Value != DBNull.Value) { e.Node.Visible = false; return; }