Before Delete

The BeforeDelete event handler enables you to take action when an XMLNode control is deleted from the document. Unfortunately, you cannot cancel the deletion. You can, however, warn users that the XMLNode will be deleted and let them undo the action. The code in Listing 6.28 shows how you can warn the user that an XMLNode control named NameFirstNameNode has been deleted from the document.

Listing 6.28. Displaying a message when an XMLNode control is deleted from a document

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

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

MsgBox(deletedControl.BaseName & " has been deleted. " _ & "Click Undo to restore the control.")

End Sub

0 0

Post a comment