I am attempting to write some back-end C# code for my InfoPath form that will set a couple of form variables when it detects that a signature has been removed from the form.
So far, I've accomplished both steps separately, but when both are run together, I get an the following error:
"Operation is not valid due to the current state of the object"
My signature removal trigger code looks like this:
public void signatures1_Changed(object sender, XmlEventArgs e) { XmlOperation op = e.Operation; if (op == XmlOperation.Delete) { if (e.OldParent.Name.Equals("my:signatures2")) { // do things when signature 2 is removed. } } }
And the function I'm using to set a value to a form field looks something like this:
private void SetFieldValue(string xPath, string xValue) { XPathNavigator xnDoc = this.MainDataSource.CreateNavigator(); XPathNavigator xnMyField = xnDoc.SelectSingleNode(xPath, this.NamespaceManager); xnMyField.SetValue(xValue); }
When I put the SetFieldValue() function calls inside that trigger, I get the aforementioned error. Since currently, the only method by which a user can remove a signature is through InfoPath's built-in Digital Signature dialog box, at the time that the "signature removed trigger" is actually called, the modal Digital Signature dialog box is still open, and I assume that since the main application window is not active, I cannot access the fields of the form.
Firstly, is this the correct assumption?
And secondly, how do I get around this?