How to close opened file and clear nodes

I create new diagram file (or open existing one).  When I do so, I will see nodes in the documentExplorer
How can I close active file so that the diagram area and the nodes in the DocumentExplorer are cleared?

9 Replies

NG Naganathan Ganesh Babu Syncfusion Team March 26, 2018 09:20 AM UTC

Hi Allen, 
 
We suggest you to use DocumentExplorer’s AttachModel()/DeattachedModel() methods to add/remove the currently loaded diagram to clear the previous model from the DocumentExplorer as per your requirement. please refer to the below code example. 
 
Code example: 
 
[VB] 
 
'Add the Diagram's model in Document explorer 
documentExplorer1.AttachModel(diagram1.Model) 
'Remove/Clear the Diagram's model in Document explorer 
documentExplorer1.DetachModel(diagram1.Model) 
 
Also refer to our online documentation link: 
 
 
Regards, 
 
Naganathan K G 



AL Allen March 26, 2018 12:56 PM UTC

Thank you Naganathan,
This has helped to remove the model in the document explorer. Is there any alert message to add in case of any changes since it was saved last,, i.e in case of unsaved changes?


NG Naganathan Ganesh Babu Syncfusion Team March 27, 2018 09:37 AM UTC

Hi Allen, 
 
The Diagram.Model contains “Modified” property which was intended to serve as a flag that get/set whenever an attribute of the diagram Model has changed. Any changes to the Model data will set the Modified property to be TRUE. Serializing the Model should ideally reset this flag. 

So, we suggest you to use that “Modified” property to check/create the alert message for the diagram changes has been saved or not in your application based on your requirement. Please refer to the below code example. 
 
Code example: 
 
[VB] 
 
If diagram1.Model.Modified Then 
'create alert message here as per your requirement... 
End If 
 
Regards, 
 
Naganathan K G 



AL Allen March 28, 2018 03:31 AM UTC

Thank you Naganathan!
I just observed two issues:
1) when I have two models in the document explorer, I cant switch to the corresponding diagram
2) when I use detach(model), I cant overwrite on existing model,, i.e to creat new model by overwriting on existing model. If I try to overwrite, the model name becomes the default 'Model'


NG Naganathan Ganesh Babu Syncfusion Team March 29, 2018 08:41 AM UTC

Hi Allen, 
 
when I have two models in the document explorer, I cant switch to the corresponding diagram 
We suggest you to use DocumentExplorer’s “AfterSelect” event to select the corresponding Diagram manually in your application. Please check our DiagramBuilder sample which is installed your machine in below mentioned location. 
 
Code example: 
 
[VB] 
 
' Subscribe for DocumentExplorer selection change 
AddHandler m_documentExplorer.AfterSelect, AddressOf m_documentExplorer_AfterSelect 
 
Private Sub m_documentExplorer_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) 
'Add your logic here... 
End Sub 
 
[Installed Drive]:\Users[username]\AppData\Local \Syncfusion\EssentialStudio\[Installed Version]\samples\Windows\ Diagram.Windows\Samples\Product Showcase\Diagram Builder 
 
when I use detach(model), I cant overwrite on existing model,, i.e to creat new model by overwriting on existing model. If I try to overwrite, the model name becomes the default 'Model' 
By default, the DocumentExplorer is set the Name as “Model” while initializing/attaching the model into the documentExplorer. We have considered this as an issue with “The Model’s Name is not updated after loading the Saved diagram” and we have logged a defect report. The fix for the issue is estimated to be available in our Volume 1 Service Pack 2 release and it will be available on end of April 2018. 
 
 
Regards, 
 
Naganathan K G 



AL Allen March 29, 2018 10:13 AM UTC

Thank you Naganathan!
I already have the documentExplorer AfterSelect event. What I wanted to do is to to switch from one model to another. For instance, with two models Model1 and Model2 in the Document Explorer Tree, I would like to see nodes of Model1 on the diagram sheet when I click on Model1. Same for Model2 in order to see the nodes corresponding to Model2 on the diagram sheet,,
What instruction can I use, say to relate my click on DocumentExplorer tree node to Diagram.View.Model??





NG Naganathan Ganesh Babu Syncfusion Team April 2, 2018 08:33 AM UTC

Hi Allen, 
 
We suggest you to use System.Windows.Forms. TreeNode’s “Tag” property to get the currently selected Model from the DocumentExplorer and set that Model into the Diagram by using Diagram’s “Model” property. Please refer to the below code example. 
 
Code example: 
 
[VB] 
 
AddHandler documentExplorer1.AfterSelect, AddressOf documentExplorer1_AfterSelect 
 
Private Sub documentExplorer1_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) 
            If TypeOf documentExplorer1.SelectedNode.Tag Is Model Then 
                diagram1.Model = TryCast(documentExplorer1.SelectedNode.Tag, Model) 
                diagram1.Refresh() 
            End If 
        End Sub 
 
Sample: 
 
 
Regards, 
 
Naganathan K G 



AL Allen April 27, 2018 01:27 PM UTC

Dear Naganathan,

Thank you so much.  I tried the piece of code you provided me.  But still the selected model doesn't switch.  Here is what I would like to do it:

I open one diagram model myModel1. This diagram has ellipse drawings which are already saved previously
Then, while myModel1 is still active, I open another model myModel2. Now I see both myModel1 and myModel2 listed in the document explorer. When I click on myModel1 in the document explorer, I would like to see the diagrams associated to it. When I do click on myModel2, I would like to witch to the diagrams associated to myModel2

The codes below do not switch from one model to another. What it does it it shows only the model which is added last, say myModel2.  Even if I click on myModel1, I always see the diagrams of myModel2

Theoretically, we could be able to open N number of different models and switch from one to another. I wonder if there is a suitable algorithm to achieve that

Many thanks


NG Naganathan Ganesh Babu Syncfusion Team May 2, 2018 09:11 AM UTC

Hi Allen, 
Please refer to the below attached document for your query. 
Regards, 
Naganathan K G 


Loader.
Up arrow icon