InfoPath - Set Field Values On Signature Removal

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?

August 28th, 2015 12:15pm

Hi

Please check if the below solves your problem

http://blogs.msdn.com/b/malag/archive/2011/05/16/error-quot-operation-is-not-valid-due-to-the-current-state-of-the-object-quot-with-custom-event-handler.aspx

http://henry-chong.com/infopath-validation-gotcha

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 1:19pm

This error may indeed have something to do with the underlying XML being in a read-only mode as stated in Mr. Chong's blog post, however, I still don't know what I can do about it.
August 28th, 2015 1:38pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics