XMLNode Control Events

The following events are available for an XMLNode control in VSTO.

• AfterInsert

• BeforeDelete

• BindingContextChanged

• ContextEnter

• ContextLeave

• ValidationError Afterlnsert

The AfterInsert event handler enables you to take action when a new XMLNode element is added to the document. Because you cannot pro-grammatically add XMLNode controls to your document at run time, it is unlikely that the AfterInsert event will be raised. It will be raised, however, if you delete an XMLNode and then click Undo. When the XMLNode control gets added back into the document, the AfterInsert event is raised. Listing 6.27 displays a message box when the XMLNode is added back into the document after a user undoes the deletion of the control.

Listing 6.27. Displaying a message when an XMLNode control is restored after deletion

Private Sub NameFirstNameNode_AfterInsert(ByVal sender _ As Object, ByVal e As Microsoft.Office.Tools.Word. _ NodeInsertAndDeleteEventArgs) Handles _ NameFirstNameNode.AfterInsert

If e.InUndoRedo Then

Dim deletedControl As Microsoft.Office.Tools _ .Word.XMLNode = Ctype(sender, _ Microsoft.Office.Tools.Word.XMLNode)

MsgBox(deletedControl.BaseName & " was restored") End If

0 0

Post a comment