Hi,Stoyan. I am sorry to ask your help again,maybe I didn’t explain my problem clearly. Below is my code:
//1.suppose dtProcess is a DataTable, and already contains several data; //2.loop every row of dtProcess, and every row would generate a ContainerNode; //3.Rearrange() method want to layout the ContainerNode collection like a tree form;
private List<ContainerNode> conList = new List<ContainerNode>(); private TreeLayout conTreeLayout = null; private DataTable dtProcess=new DataTable(); private ContainerNode rootContainer=null; int containerID=0; ....... private void DrawContainerTree() { diagram.ClearAll(); DrawContainerNodes(); LinksContainers(); container_Rearrange(); } private void DrawContainerNodes() { for (int i = 0; i < dtProcess.Rows.Count; i++) { if (dtProcess.Rows[i]["process"].ToString() != null) { ContainerNode conNode = diagram.Factory.CreateContainerNode(xLocation, yLocation, width + 10, height + 10); conNode.Font = new Font("Arial", 4, GraphicsUnit.World); conNode.Caption = dtProcess.Rows[i]["process"].ToString(); conNode.Tag = dtProcess.Rows[i]["up_process"].ToString(); conNode.Foldable = true; conNode.Folded = true; conNode.AutoShrink = true; conNode.Expandable = true; conNode.AnchorPattern = MindFusion.Diagramming.AnchorPattern.TopInBottomOut; if (conNode.Tag.ToString()=="") { rootContainer = conNode; diagram.Nodes.Add(rootContainer); } //add every ContainerNode to the conList conList.Add(conNode); containerID++; } } }
private void LinksContainers() { foreach (ContainerNode upNode in conList) { if (upNode == null) continue; foreach (ContainerNode downNode in conList) { if (downNode == null) continue; if (downNode.Tag.ToString() == upNode.Caption) { //if downNode's up_process is upNode, then attach the downNode to the Group of upNode downNode.AttachTo(upNode, AttachToNode.BottomCenter); //link downNode and upNode DiagramLink link = diagram.Factory.CreateDiagramLink(upNode, downNode); } } } } private void Rearrange() { conTreeLayout = new TreeLayout(rootContainer, TreeLayoutType.Centered, false, TreeLayoutLinkType.Cascading3, TreeLayoutDirections.TopToBottom, levelDistance + 5, nodeDistance + 2, false, new SizeF(1, 1));
conTreeLayout.Arrange(diagram); diagram.ResizeToFitItems(1, true); } At last: all the ContainerNodes are empty, it just like a Node,contain none of children nodes in it.I want to arrange them automatically and being a tree. Thans a lot!
|