We have an application in which we can create diagrams (flowcharts) that may be loaded and saved to and from a database.
Usually this functionality works fine but I am getting an exception in the following scenario:
I open an existing diagram, select a node on it and then press ‘F2’ to edit the text associated with that node.
Without changing the text and with the node’s text editor box still visible I then select the application’s ‘Save’ option, to save the diagram to the database.
The following exception is then thrown:
"Object reference not set to an instance of an object."
I’ve traced this exception to a call to GraphView.GraphDoc.StartTransaction() which happens right at the start of the ‘Save’ process.
Is there a way that I can check for and cancel/close any existing node text edits just prior to performing the ‘Save’ process to prevent this exception?
I’d like to get a stack dump of that exception…
Seems the issue was to do with a null GraphView object. Just prior to the StartTransaction() call there was a call to a function which returned the currently active GraphView, specifically:
return this.ActiveMdiChild.ActiveControl as GraphView;
This function call worked when none of the nodes on the diagram were being edited, but when a node was being edited it was returning a null. Reason being that during node editing, the ActiveControl call was returning the following object type:
As this is not a GraphView then a null was being returned hence the knock-on error in the StartTransaction() call.
To fix have re-coded it to get the current GraphView object from the current GraphViewWindow object instead and now also test for a GraphView object value before trying to work with it (a basic programming rule I know but in my defence I didn’t code the above!).
Thanks also for the note about using DoEndEdit() - it worked a charm to cancel the node editing mode.
Actually, I think you got that code from our samples. I don’t think anyone else has ever had a problem
with it, but I’ll put that on my to-do list.