Export (0) Print
Expand All

FormErrorCollection class

Contains a FormError object for each error in the current form.

System.Object
  Microsoft.Office.InfoPath.FormErrorCollection

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

public abstract class FormErrorCollection : IEnumerable

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.

NoteNote

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;

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);

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft