Export (0) Print
Expand All

View2.ExecuteAction Method

Executes a Microsoft Office InfoPath 2007 editing command against a form's underlying XML document, based on the data selected in the view.

This method is not CLS-compliant.  

Namespace: Microsoft.Office.Interop.InfoPath.SemiTrust
Assembly: Microsoft.Office.Interop.InfoPath.SemiTrust (in microsoft.office.interop.infopath.semitrust.dll)

Parameters

bstrAction

The name of the editing action to perform.

varXmlToEdit

The name of the field or group to which to apply the editing action. This is equivalent to the value of the name attribute in the xmlToEdit element of the form definition (.xsf) file.

The ExecuteAction method is used to programmatically perform built-in InfoPath editing actions against a form's underlying XML document, based on the selected context in a view.

The action that is executed will be the same action that would be used when clicking on an equivalent menu or toolbar button; namely one for which the button element in the .xsf file has corresponding xmlToEdit and action attributes. As with using a button, the action will be based on current selection: it will act on the selected context (and in the case where the selection would lead the button to be disabled, then the ExecuteAction method will have no effect).

It is possible to first set the selection context by using the SelectNodes method or SelectText method, then call the ExecuteAction method to act on that context.

The ExecuteAction method will return an error for the following reasons:

  • The bstrAction parameter does not contain a valid editing component name.

  • The varXmlToEdit parameter does not match an editing component that is defined in the view.

  • The varXmlToEdit parameter is required for a specific editing action.

  • The editing action is not applicable to the selected context.

  • The following is a table of parameter combinations that can be used with the ExecuteAction method.

Combination

Description

"Copy"

Copies the selected data to the clipboard.

"Paste"

Copies data from the clipboard to the insertion point.

"Cut"

Removes the selected data and copies it to the clipboard.

"Delete"

Deletes the selected data.

"xCollection::insert", "xmlToEdit"

Inserts data based on the selected context using the xCollection editing component. If current selection is within a container of the xCollection, specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is appended within that container.

"xCollection::insertBefore", "xmlToEdit"

Inserts data before the selected context using the xCollection editing component. If current selection is within an item of the xCollection, as specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is inserted before that item.

"xCollection::insertAfter", "xmlToEdit"

Inserts data after the selected context using the xCollection editing component. If current selection is within an item of the xCollection, as specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is inserted after that item.

"xCollection::remove", "xmlToEdit"

Deletes data from the selected context using the xCollection editing component. If current selection is within an item of the xCollection, as specified by its xmlToEdit element in the .xsf, then that item is deleted.

"xCollection::removeAll", "xmlToEdit"

Deletes all data contained within the selected context using the xCollection editing component. If current selection is within a container of the xCollection, as specified by the xmlToEdit element in the .xsf, then this action deletes all the items within that container.

"xReplace::replace", "xmlToEdit"

Replaces the data in the selected context using the xReplace editing component. If current selection is within an item of the xReplace, as specified by its xmlToEdit element in the .xsf, then that item is replaced by the fragmentToInsert element data.

"xOptional::insert", "xmlToEdit"

Inserts data based on the selected context using the xOptional editing component. If current selection is within an container of the xOptional, as specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is appended within that container.

"xOptional::remove", "xmlToEdit"

Deletes data from the selected context using the xOptional editing component. If current selection is within an item of the xOptional, as specified by its xmlToEdit element in the .xsf, then that item is deleted.

Note   In some cases, calling the ExecuteAction method from the OnClick for a button in a view may cause an error. This is because the selected context changes to the button when the button is clicked. In this case, it is better to use a button (or link) on a custom task pane, toolbar, or menu to call the ExecuteAction method.

ImportantImportant:

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.

In the following example, the ExecuteAction method of the ViewObject object is used to delete selected data and place it on the clipboard:

thisXDocument.View.ExecuteAction("Cut", Type.Missing);

In the following example, the ExecuteAction method of the ViewObject object is used to insert data using the xCollection editing component, based on the selected context:

thisXDocument.View.ExecuteAction("xCollection::insert", "group1_1");

Community Additions

Show:
© 2014 Microsoft