Share via


XMLNodes.AfterInsert Event (2007 System)

Occurs when the user adds a new XMLNode to the collection or to one of its descendents.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

Syntax

'Declaration
Public Event AfterInsert As NodeInsertAndDeleteEventHandler
'Usage
Dim instance As XMLNodes 
Dim handler As NodeInsertAndDeleteEventHandler 

AddHandler instance.AfterInsert, handler
public event NodeInsertAndDeleteEventHandler AfterInsert
public:
 event NodeInsertAndDeleteEventHandler^ AfterInsert {
    void add (NodeInsertAndDeleteEventHandler^ value);
    void remove (NodeInsertAndDeleteEventHandler^ value);
}
JScript does not support events.

Examples

The following code example demonstrates event handlers for the AfterInsert and BeforeDelete events. The code displays a message box before a XMLNode is deleted from the document and after a XMLNode is added to the document. The example also uses the Add method to add a new element to an XMLNodes collection at a specified range and programmatically raise the AfterInsert event. This example assumes that the current document contains an XMLNodes collection named SampleInsertNodes, which has a parent XMLNode named SampleNode.

Private Sub XMLNodeAddAndDelete()
    Dim range1 As Object = Me.SampleInsertNodes(1).Range

    ' This will raise the AfterInsert event. 
    Dim node1 As Word.XMLNode = _
        Me.SampleInsertNodes.Add("MemoFrom", _
        Me.SampleNode.NamespaceURI, range1)
End Sub 

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

    If e.InUndoRedo Then
        MessageBox.Show("A child element of SampleInsertNodes was " & _
            "inserted as a result of an undo or redo operation.")
    Else
        MessageBox.Show("A child element of SampleInsertNodes " & _
            "was inserted.")
    End If 
End Sub 

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

    If e.InUndoRedo Then
        MessageBox.Show("A child element of SampleInsertNodes " & _
            "is about to be deleted as a result of an undo or " & _
            "redo operation.")
    Else
        MessageBox.Show("A child element of SampleInsertNodes " & _
        "is about to be deleted.")
    End If 
End Sub
private void XMLNodeAddAndDelete()
{
    object range1 = this.SampleInsertNodes[1].Range;

    this.SampleInsertNodes.AfterInsert +=
        new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
        SampleInsertNodes_AfterInsert);

    this.SampleInsertNodes.BeforeDelete +=
        new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
        SampleInsertNodes_BeforeDelete);

    // This will raise the AfterInsert event.
    Word.XMLNode node1 = this.SampleInsertNodes.Add("MemoFrom",
        this.SampleNode.NamespaceURI, ref range1);
}

void SampleInsertNodes_AfterInsert(object sender,
    Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
    if (e.InUndoRedo)
    {
        MessageBox.Show("A child element of SampleInsertNodes was " +
            "inserted as a result of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show("A child element of SampleInsertNodes " +
            "was inserted.");
    }
}

void SampleInsertNodes_BeforeDelete(object sender,
    Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
    if (e.InUndoRedo)
    {
        MessageBox.Show("A child element of SampleInsertNodes " +
            "is about to be deleted as a result of an undo or " +
            "redo operation.");
    }
    else
    {
        MessageBox.Show("A child element of SampleInsertNodes " +
            "is about to be deleted.");
    }
}

.NET Framework Security

See Also

Reference

XMLNodes Class

XMLNodes Members

Microsoft.Office.Tools.Word Namespace