Version

OnBeforePaste Method

Called before nodes are pasted from the clipboard.
Syntax
'Declaration
 
Protected Overridable Sub OnBeforePaste( _
   ByVal e As BeforePasteEventArgs _
) 
protected virtual void OnBeforePaste( 
   BeforePasteEventArgs e
)

Parameters

e
An System.EventArgs that contains the event data.
Example
The following sample code illustrates some of the information available in the BeforePaste event.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports Infragistics.Win
Imports Infragistics.Win.UltraWinTree

Private Sub ultraTree1_BeforePaste(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinTree.BeforePasteEventArgs) Handles ultraTree1.BeforePaste

    Dim sb As New System.Text.StringBuilder()
    Dim node As UltraTreeNode
    Dim dr As DialogResult

    ' Setting the Tag of the Nodes collection passed into the BeforeCut
    ' and BeforeCopy events to some serializable value can be used to
    ' identify the tree that copied the nodes to the clipboard. This Tag
    ' value will be de-serialized and set on the Nodes collection that is
    ' passed into the BeforePaste event. This can be used for preventing 
    ' paste operations between trees.

    ' If these nodes weren't copied from this tree then cancel the paste
    If e.Nodes.Tag <> Me.ultraTree1.GetHashCode() Then
        e.Cancel = True
        Exit Sub
    End If

    ' Note: The BeforePaste event will be raised even if there are no
    ' nodes on the clipboard. This is done to allow other clipboard formats
    ' to be checked.

    ' The ParentNode property can be changed to specify where the
    ' pasted nodes will go. A value of Nothing will make them root nodes.
    e.ParentNode = Nothing

    ' Setting the index property will cause the nodes to be pasted
    ' in the parent's Nodes collection at that index. In this case
    ' setting the index to 0 will paste the nodes before any other
    ' nodes in the collection.
    e.Index = 0

End Sub
using System.Diagnostics;
using Infragistics.Win;
using Infragistics.Win.UltraWinTree;


private void ultraTree1_BeforePaste(object sender, Infragistics.Win.UltraWinTree.BeforePasteEventArgs e)
{
	// Setting the Tag of the Nodes collection passed into the BeforeCut
	// and BeforeCopy events to some serializable value can be used to
	// identify the tree that copied the nodes to the clipboard. This Tag
	// value will be de-serialized and set on the Nodes collection that is
	// passed into the BeforePaste event. This can be used for preventing 
	// paste operations between trees.

	// If these nodes weren't copied from this tree then cancel the paste
	if ( (int)e.Nodes.Tag != this.ultraTree1.GetHashCode() )
	{
		e.Cancel = true;
		return;
	}
		
	// Note: The BeforePaste event will be raised even if there are no
	// nodes on the clipboard. This is done to allow other clipboard formats
	// to be checked.

	// The ParentNode property can be changed to specify where the
	// pasted nodes will go. A value of null will make them root nodes.
	e.ParentNode = null;

	// Setting the index property will cause the nodes to be pasted
	// in the parent's Nodes collection at that index. In this case
	// setting the index to 0 will paste the nodes before any other
	// nodes in the collection.
	e.Index = 0;
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also