Export (0) Print
Expand All

XMLNode.ValidationError Event

Occurs when there is a validation error in the XMLNode control.

Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word (in microsoft.office.tools.word.dll)

public event EventHandler ValidationError

The following code example uses the SetValidationError method to set a custom validation error message for an XMLNode. An event handler for the ValidationError event displays the custom validation error message if the XMLNode does not validate. This example assumes that the current document contains two XMLNode objects named CustomerAddress1Node and CustomerZipNode that map to schema elements with an integer data type.

private void XMLNodeValidationError()
{
    // Set custom error message for Address1 element.
    string errorText = this.CustomerAddress1Node.BaseName + 
        " element must be an integer.";
    object objErrorText = (object)errorText;
    this.CustomerAddress1Node.SetValidationError(
        Word.WdXMLValidationStatus.wdXMLValidationStatusCustom,
        ref objErrorText, false);

    // Attach validation event handlers.
    this.CustomerZipNode.ValidationError +=
        new EventHandler(CustomerNode_ValidationError);
    this.CustomerAddress1Node.ValidationError +=
        new EventHandler(CustomerNode_ValidationError);

    // This does not raise a validation error.
    int val = 22222;
    this.CustomerZipNode.NodeText = val.ToString();
    
    // This raises a validation error.
    this.CustomerAddress1Node.NodeText = 
        "Seventeen Hundred Twenty One";
}

void CustomerNode_ValidationError(object sender, EventArgs e)
{
    Microsoft.Office.Tools.Word.XMLNode tempNode = 
        (Microsoft.Office.Tools.Word.XMLNode)sender;

    MessageBox.Show("Error: " + tempNode.ValidationErrorText[false]);
}

Show:
© 2015 Microsoft