NodeInsertAndDeleteEventHandler Delegate

Definition

Represents the method that handles the AfterInsert and BeforeDelete events of an XMLNode control, and the AfterInsert and BeforeDelete events of an XMLNodes control.

public delegate void NodeInsertAndDeleteEventHandler(System::Object ^ sender, NodeInsertAndDeleteEventArgs ^ e);
public delegate void NodeInsertAndDeleteEventHandler(object sender, NodeInsertAndDeleteEventArgs e);
type NodeInsertAndDeleteEventHandler = delegate of obj * NodeInsertAndDeleteEventArgs -> unit
Public Delegate Sub NodeInsertAndDeleteEventHandler(sender As Object, e As NodeInsertAndDeleteEventArgs)

Parameters

sender
Object

The source of the event.

Examples

The following code example demonstrates event handlers for the AfterInsert and BeforeDelete events. These event handlers display a message box before an XMLNode is deleted from the document, and after an XMLNode is added to the document. The example also uses the RemoveChild method to delete a node and programmatically raise the BeforeDelete event. This example assumes that the current document contains an XMLNode named CustomerNode that contains a child node named CustomerDateNode.

private void XMLNodeInsertAndDelete()
{
    this.CustomerDateNode.AfterInsert +=
        new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
        XMLNode_AfterInsert);

    this.CustomerDateNode.BeforeDelete +=
        new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
        XMLNode_BeforeDelete);

    this.CustomerNode.RemoveChild(this.CustomerDateNode.InnerObject);
}

void XMLNode_BeforeDelete(object sender, 
    Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
    Microsoft.Office.Tools.Word.XMLNode tempNode =
        (Microsoft.Office.Tools.Word.XMLNode)sender;

    if (e.InUndoRedo)
    {
        MessageBox.Show(tempNode.BaseName + " element is about to be " +
            "deleted as a result of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(tempNode.BaseName + " element is about to be " +
            "deleted.");
    }
}


void XMLNode_AfterInsert(object sender,
    Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
    Microsoft.Office.Tools.Word.XMLNode tempNode =
        (Microsoft.Office.Tools.Word.XMLNode)sender;

    if (e.InUndoRedo)
    {
        MessageBox.Show(tempNode.BaseName + " element was " +
            "inserted as a result of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(tempNode.BaseName + " element was inserted.");
    }
}
Private Sub XMLNodeInsertAndDelete()
    Me.CustomerNode.RemoveChild(Me.CustomerDateNode.InnerObject)
End Sub

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

    Dim tempNode As Microsoft.Office.Tools.Word.XMLNode = _
        CType(sender, Microsoft.Office.Tools.Word.XMLNode)
    If e.InUndoRedo Then
        MsgBox(tempNode.BaseName & " element is about to be " & _
            "deleted as a result of an undo or redo operation.")
    Else
        MsgBox(tempNode.BaseName & " element is about to be " & _
            "deleted.")
    End If
End Sub

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

    Dim tempNode As Microsoft.Office.Tools.Word.XMLNode = _
        CType(sender, Microsoft.Office.Tools.Word.XMLNode)

    If e.InUndoRedo Then
        MsgBox(tempNode.BaseName & " element was " & _
            "inserted as a result of an undo or redo operation.")
    Else
        MsgBox(tempNode.BaseName & " element was inserted.")
    End If
End Sub

Remarks

When you create a NodeInsertAndDeleteEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, until you remove the delegate.

Applies to