FormErrorCollection.Add Method (XPathNavigator, String, String, String, Int32, ErrorMode)

Creates and adds a new FormError to the FormErrorCollection object associated with the current form.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

Syntax

'Declaration
Public MustOverride Function Add ( _
    context As XPathNavigator, _
    name As String, _
    message As String, _
    messageDetails As String, _
    errorCode As Integer, _
    errorMode As ErrorMode _
) As FormError
'Usage
Dim instance As FormErrorCollection
Dim context As XPathNavigator
Dim name As String
Dim message As String
Dim messageDetails As String
Dim errorCode As Integer
Dim errorMode As ErrorMode
Dim returnValue As FormError

returnValue = instance.Add(context, name, _
    message, messageDetails, errorCode, _
    errorMode)
public abstract FormError Add(
    XPathNavigator context,
    string name,
    string message,
    string messageDetails,
    int errorCode,
    ErrorMode errorMode
)

Parameters

  • name
    Type: System.String

    The name of the error (cannot be blank).

  • messageDetails
    Type: System.String

    The detailed message for the error.

Return Value

Type: Microsoft.Office.InfoPath.FormError
A reference to the new FormError that was added to the collection.

Exceptions

Exception Condition
ArgumentException

The name is a null reference (Nothing in Visual Basic) or an empty string.

ArgumentException

An error of the same name already exists in the collection.

ArgumentNullException

The parameters passed to this method are a null reference (Nothing in Visual Basic).

ArgumentException

The parameters passed to this method arenot valid. For example, they are of the wrong type or format.

Remarks

The FormErrorType of the new FormError will be set to UserDefined.

Note

It is possible to add multiple errors with the same name parameter value to different context nodes. However, if you add an error with the same name to the same context node twice, the second error added overwrites the first one.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.

Examples

In the following example, first an XPathNavigator object is positioned at the field with which to associate an error. Then, the XPathNavigator, name, message, detailed message, error code, error number, and error display mode are passed to the Add method of the FormErrorCollection class to add the error to the form's error collection.

XPathNavigator root, txtbox;
// Create XPathNavigator for main data source.
root = this.MainDataSource.CreateNavigator();

// Create XPathNavigator positioned at field to associate with error.
txtbox = root.SelectSingleNode("//my:field1", this.NamespaceManager);

// Get form's collection of errors and add error.
this.Errors.Add(txtbox, "Field1Error", "Short error message.", 
   "Detailed error description.", 102057, ErrorMode.Modeless);
Dim root, txtbox As XPathNavigator
' Create XPathNavigator for main data source.
root = Me.MainDataSource.CreateNavigator()

' Create XPathNavigator positioned at field to add error.
txtbox = root.SelectSingleNode("//my:field1", Me.NamespaceManager)

' Get form's collection of errors and add error.
Me.Errors.Add(txtbox, "Field1Error", "Short error message.", 
   "Detailed error description.", 102057, ErrorMode.Modeless)

See Also

Reference

FormErrorCollection Class

FormErrorCollection Members

Add Overload

Microsoft.Office.InfoPath Namespace