We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Add multiple nodes with InsertNodesCmd

i am just evaluating Essential Diagram and have not found an answer for my question in the online help, forums and knowledge base. So i try it this way :-) The example i am implementing has to add a few hundred nodes and edges prgrammatically. So i thought of using InsertNodesCmd and i like the realization of the command pattern in Essential Diagram very much. But i did not find an example of adding multiple nodes to different locations at once. I think it is not practical hundreds of node one upon the other. And creating e.g. 500 command objects, initializing them with a node object, setting location and executing them does really take a long time. So i need to speed it up somehow. I also didn''t get SuspendLayout to work. I thought it stops instant drawing of each node i add to the diagram view. But it won''t do. This is what i did in an AddNodes routine: InsertNodesCmd myCmd; Symbol myTransition; this.diagram1.SuspendLayout(); for ( int i=0 ; i<500 ; i++ ) { myCmd = new InsertNodesCmd(); myTransition = new NodeTransition(); myPosX = myRandom.Next(cWidth - 100)); myPosY = myRandom.Next(cHeight - 100)); myCmd.Nodes.Add(myTransition); myCmd.Location = new Point(myPosX, myPosY); this.diagram1.Controller.ExecuteCommand(myCmd); } this.diagram1.ResumeLayout(); Any suggestion for speeding up is highly welcome :-) Jörn

11 Replies

AD Administrator Syncfusion Team August 22, 2005 03:05 PM UTC

diagramControl.Model.AppendChild or AppendChildren is much faster. However, if you choose this method then you will lose undo functionality for these nodes that you added. Also, SuspendLayout is not a diagram control method. It is Control.SuspendLayout and is used by the control for adding child controls. The method you are looking for is: this.diagram1.BeginUpdate(); //add nodes this.diagram1.EndUpdate(); this.diagram1.Refresh();


JZ Jörn Zietz August 22, 2005 04:00 PM UTC

> diagramControl.Model.AppendChild or > AppendChildren is much faster. However, if you > choose this method then you will lose undo > functionality for these nodes that you added. Thx Kevin. I dont really need undo while programmatically building network but command pattern seems to be much prettier :-) But i will compare AddChildren with commands. > ... > this.diagram1.BeginUpdate(); > //add nodes > this.diagram1.EndUpdate(); > this.diagram1.Refresh(); Unfortunately this does not work (at least with InsertNodesCmd) -- diagram1 is still updated after every added node. Does anyone have an idea how to use InsertNodesCmd with multiple nodes?


JZ Jörn Zietz August 22, 2005 04:01 PM UTC

> diagramControl.Model.AppendChild or > AppendChildren is much faster. However, if you > choose this method then you will lose undo > functionality for these nodes that you added. Thx Kevin. I dont really need undo while programmatically building network but command pattern seems to be much prettier :-) But i will compare AddChildren with commands. > ... > this.diagram1.BeginUpdate(); > ...add nodes... > this.diagram1.EndUpdate(); > this.diagram1.Refresh(); Unfortunately this does not work (at least with InsertNodesCmd) -- diagram1 is still updated after every added node. Does anyone have an idea how to use InsertNodesCmd with multiple nodes?


JZ Jörn Zietz August 22, 2005 04:01 PM UTC

> diagramControl.Model.AppendChild or > AppendChildren is much faster. However, if you > choose this method then you will lose undo > functionality for these nodes that you added. Thx Kevin. I dont really need undo while programmatically building network but command pattern seems to be much prettier :-) But i will compare AddChildren with commands. > ... > this.diagram1.BeginUpdate(); > ...add nodes... > this.diagram1.EndUpdate(); > this.diagram1.Refresh(); Unfortunately this does not work (at least with InsertNodesCmd) -- diagram1 is still updated after every added node. Does anyone have an idea how to use InsertNodesCmd with multiple nodes?


JZ Jörn Zietz August 22, 2005 04:02 PM UTC

Sorry for triple posting. First two times i got an error message because of ''ö'' in my name :-(


AD Administrator Syncfusion Team August 22, 2005 04:54 PM UTC

Hello Jörn, Using the Diagram.Model.BeginUpdate()/EndUpdate() sequence before and after you perform your node insertion should prevent the diagram model/view components from being updated. This should work with both the command classes and the Model.AppendChild methods. We demonstrate both approaches of populating multiple nodes in the ''InDepth\OrgLayout'' and ''InDepth\Expander'' samples that ship with the product. To be doubly sure I tested this scenario and it works as expected using the latest 3.3.0.0 codebase that I am currently running. Our current evaluation build uses an older 3.2 level code, and it is possible that the BeginUpdate/EndUpdate implementation might have a problem in that version. Please send an email to ''prakashs@syncfusion.com'' requisitioning an evaluation of Essential Studio v.3.3.0.0, and I can provide you with the download instructions for an eval build that uses the 3.3 version. This later code will let you avoid this problem, and will let you avail of some new fixes/features/samples that have been added for that update. We are on the verge of shipping the final version of Essential Studio 3.3.0.0, and the evaluation download will be udpated for that version shortly thereafter. Regards, Prakash Surendra Syncfusion Inc.,


AD Administrator Syncfusion Team August 22, 2005 05:25 PM UTC

Sorry Jörn, I gave you incorrect information. I said to use diagram.BeginUpdate() but that method is not diagram specific (but it works for AppendChild). As Prakash said, it should really be diagram.Model.BeginUpdate(). The InsNodesCmd is fast when this method is used. On a side note, I have been using the Syncfusion Diagram component for about a year now, and it really is amazing. Its easy to use, very powerful and extensible, and Syncfusion''s support is fantastic. Two thumbs up from me. Kevin


JZ Jörn Zietz August 23, 2005 10:46 AM UTC

Thx Prakash, it works fine with both versions (3.2.1.0 and 3.3.0.0). I mistakenly tried ''diagram1.BeginUpdate()'' instead of ''diagram1.Model.BeginUpdate()'' :-( But i still would like to know if there is a way to add e.g. 500 Nodes in one step. I can only add the node one upon another: //---- this.diagram1.Model.BeginUpdate(); myCmd = new InsertNodesCmd(); for ( int i=0 ; i<500 ; i++ ) { myTransition = new NodeTransition(); myTransition.Name = System.Convert.ToString(i); myCmd.Nodes.Add(myTransition); } myCmd.Location = new Point(100, 100); this.diagram1.Controller.ExecuteCommand(myCmd); this.diagram1.Model.EndUpdate(); //---- Is there a way to create a batch of nodes relativly placed to each other an add them with ''InsertNodesCmd'' to the model?


AD Administrator Syncfusion Team August 23, 2005 02:35 PM UTC

Hi Jörn, Have you tried using the InsertNodesCmd.Offset property with the version of the InsertNodesCmd.Nodes.Add(INodeCollection, int) method that lets you add a batch of nodes to the insert command''s nodes collection? Thanks, Prakash Surendra Syncfusion Inc.,


JZ Jörn Zietz August 24, 2005 02:56 PM UTC

Hi Prakash, thanks again :-) I haven''t had the time so far but i will try these days. Reading online help and searching examples does not give a clue so far...


AD Administrator Syncfusion Team August 25, 2005 02:44 PM UTC

Jörn, My apologies that you''ve been having difficulty locating some of these more esoteric functionality in Essential Diagram. We are constantly trying to improve the quality and content of the product documentation and samples, and I assure you that this will progressively get better in future updates of the product. Regards, Prakash Surendra Syncfusion Inc.,

Loader.
Live Chat Icon For mobile
Up arrow icon