FormErrorCollection class
Contains a FormError object for each error in the current form.
Inheritance hierarchy
System.Object
Microsoft.Office.InfoPath.FormErrorCollection
Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)
Syntax
'Declaration
Public MustInherit Class FormErrorCollection _
Implements IEnumerable
'Usage
Dim instance As FormErrorCollection
public abstract class FormErrorCollection : IEnumerable
Remarks
A FormErrorCollection object contains a collection of FormError objects that represent all errors occurring in the associated form. The collection of errors includes validation errors, system-generated errors, and user-defined (custom) errors. The FormErrorCollection class provides properties and methods for adding, deleting, and gaining access to the FormError objects that it contains. You cannot delete validation or system-generated errors from this collection.
In addition to managing the errors generated by InfoPath, the FormErrorCollection class can also be used to create custom errors using the Add method.
Note
Custom errors can also be created using the ReportError method of the XmlValidatingEventArgs class.
To access the FormErrorCollection object associated with a form, use the Errors property of the XmlForm class.
FormErrorCollection myErrors = this.Errors;
Dim myErrors As FormErrorCollection = Me.Errors
Examples
In the following example, first an XPathNavigator object is positioned at the field with which to associate an error. Then, the XPathNavigator and error message details 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)
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.