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
close icon

Diagram has changed event ?

I''m working on a diagram application where i would like to show the user a warning message to save the diagram before leaving the diagram form.

Is there any event which is fired after changes have made to the diagram content ?

Thanks in advance,

Joerg

8 Replies

J. J.Nagarajan Syncfusion Team October 11, 2006 02:44 PM UTC

Hi Joerge,

If your intention is to show the user a warning message to save the diagram before leaving the diagram form then you can use "DiagramForm_Closing" event. Please refer to our Diagram Builder sample(C:\Program Files\Syncfusion\Essential Studio\4.3.0.30\Windows\Diagram.Windows\Samples\In Depth\DiagramBuilder). In this sample when you close the Diagram Form you can get a warning message box to save the Diagram. Please kindly refer to it and let me know if you have any questions.

Currently our Diagram control supports ChildrenChangeComplete event which is fired after changes have made to the diagram content. Please let me know if this helps for you.If this doesn''''t helps please give us some more details about your requirement.

Thanks for your interest in Essential Diagram.

Regards,
Nagaraj


JS Joerg Spengler October 12, 2006 07:42 AM UTC

Hi Nagarajan,

i have looked into the code of the "DiagramForm_Closing" method in the DiagramBuilder sample, but i do not understand it, specially the usage of the propertyeditor object.

In my application i have a form with 2 textboxes and 1 diagram. The TextChanged events of the 2 textboxes and the ChildrenChangeComplete and some other events of the diagram are handled in a method of the form, where i enable the save baritem and mark the document as changed. In the form closing event i check if the document was changed & saved, otherwise the user will get a warning message box.

Actually this works fine, with the exception that no event is fired, if the size of a node has changed(resizing symbol with mouse or in the property grid).

Best regards,

Joerg


J. J.Nagarajan Syncfusion Team October 12, 2006 08:43 PM UTC

Hi Joerg,

Sorry for the inconvenience caused. Actually our Diagram Builder sample is a MDI application. The usage of the propertyeditor object in the Form_Closing event of DiagramForm.cs is to release the property editor.If your intention is to show the user a warning message to save the diagram before leaving the diagram form then you can use the following code snippet in Form closing event

//In Diagram Form closing event
if (this.diagram1.Model.Modified)
{
DialogResult res = MessageBox.Show(this, "The diagram has been modified. Save changes?", "Save changes", MessageBoxButtons.YesNoCancel);
if (res == DialogResult.Yes)
{
if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
{
this.diagram1.SaveBinary(this.saveFileDialog1.FileName);
MessageBox.Show("The Digram has been stored successfully");
}
else
{
e.Cancel = true;
}
}
else if (res == DialogResult.Cancel)
{
e.Cancel = true;
}
}

I have attached the sample which demonstrate this completely. In this sample when you close the diagram form after made ame changes on diagram a message box will alert you to save teh diagram.

I hope this will meet your requirement. Please let me know if you have any questions.

Regards,
Nagaraj

DiagramClosingIssue.zip


JS Joerg Spengler October 13, 2006 04:20 AM UTC

Thanks a lot for this fast and simple solution.

Best regards,

Joerg


J. J.Nagarajan Syncfusion Team October 25, 2006 04:33 PM UTC

Hi Jeorg,

Thanks for the update. Please feel free to contact us if you have any other concerns.

Thanks for your interest in Essential Diagram.

Regards,
Nagaraj


LM Lan Mo April 18, 2007 06:43 PM UTC

Hi,
V4.4.0.51 & VS2003

I use following code to load diagram from IMAGE field in SQL SERVER. I found the line this.diagram.LoadBinary(ms);
always make this.diagram.Model.Modified=true. That caused always ask user to save the diagram even it has not been modified since it was loaded. In form close event, I prompt user to save diagram when this.diagram.Model.Modified=true
How can I avoid it?

by the way, I found this.diagram1.LoadBinary(this.openFileDialog1.FileName)-- load from a file make this.diagram.Model.Modified to false. That is correct.

Thanks,

Lan




//Notes: Diagram has been saved as binary stream in "IMAGE" field in a SQLServer table.
private void LoadTree()
{
this.diagram.Model.Clear(); //this make this.diagram.Model.Modified=false
// Load diagram from a "IMAGE" field in a SQLServer table.
byte[] MyData=new byte[0];
DataView dvTree=dtTree.DefaultView;
dvTree.RowFilter=string.Format("tree_set={0} and pavetype={1} and funcls={2}",
mTreeSet,mPaveType,mFuncClass);
if (dvTree.Count==1)
{
DataRowView myRow=dvTree[0];
if (myRow["diagram"]!=DBNull.Value)
{
MyData =(byte[])myRow["diagram"];
// memorystream
MemoryStream ms=new MemoryStream(MyData,0,MyData.Length);
this.diagram.LoadBinary(ms); //this make this.diagram.Model.Modified=true
}
}
}


J. J.Nagarajan Syncfusion Team April 18, 2007 11:47 PM UTC

Hi Lan,

You can just resolve this issue by setting false value to Model.Modified property after the LoadBinary() method. Please refer to the following code snippet

if (myRow["diagram"]!=DBNull.Value)
{
MyData =(byte[])myRow["diagram"];
// memorystream
MemoryStream ms=new MemoryStream(MyData,0,MyData.Length);

this.diagram.LoadBinary(ms);
this.diagram.Model.Modified=false;
}

Please test on your side with this code and let me know if you have any poblem.

Thanks,
Nagaraj


LM Lan Mo April 19, 2007 03:03 PM UTC

Hi Nagaraj,
Thanks for help. It works for me.

Actually, I've made simple stupid mistake regarding the property 'diagram.Model.Modified'. When I read its help info "Flag indicating if the model has been monidifed", I thought it is read-only property and never tried to reset it to false.

Thanks again. Have a great day!

Lan

Loader.
Live Chat Icon For mobile
Up arrow icon