Version

BeforeSelect Event

Occurs before a tree node is selected.
Syntax
'Declaration
 
Public Event BeforeSelect As BeforeNodeSelectEventHandler
public event BeforeNodeSelectEventHandler BeforeSelect
Event Data

The event handler receives an argument of type BeforeSelectEventArgs containing data related to this event. The following BeforeSelectEventArgs properties provide information specific to this event.

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
IncludeCollapsedDescendantsOnRangeSelection Gets/sets whether the descendants of collapsed nodes are selected when those collapsed nodes lie between the first and last node in a range selection.
NewSelections The new SelectedNodes, if the event is not cancelled.
Remarks

The BeforeSelectEventArgs.NewSelections property of the BeforeSelectEventArgs contains a collection of the UltraTreeNode objects that are about to be selected.

Setting the System.ComponentModel.CancelEventArgs.Cancel property to true will prevent the UltraTreeNode objects from being selected.

Example
The following sample code illustrates some of the information available in the BeforeSelect 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.UltraWinTree

Private Sub ultraTree1_BeforeSelect(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinTree.BeforeSelectEventArgs) Handles ultraTree1.BeforeSelect

    Dim sb As New System.Text.StringBuilder()

    sb.Append("The SelectedNodes collection is about to change to the nodes ")

    Dim node As UltraTreeNode

    ' Loop over the nodes that will be in the new SelectedNodes collection.
    ' Note: The Nodes collection exposed by the event args
    ' is read-only.
    For Each node In e.NewSelections
        sb.Append(node.Key)
        sb.Append(", ")
    Next

    sb.Append(" Press ''OK'' or ''Cancel''.")

    Dim dr As DialogResult

    dr = MessageBox.Show(Me, _
     sb.ToString(), _
     "Selected nodes changing", _
     MessageBoxButtons.OKCancel)

    If dr = DialogResult.Cancel Then e.Cancel = True

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

private void ultraTree1_BeforeSelect(object sender, Infragistics.Win.UltraWinTree.BeforeSelectEventArgs e)
{

	System.Text.StringBuilder sb = new System.Text.StringBuilder();

	sb.Append("The SelectedNodes collection is about to change to the nodes ");

	// Loop over the nodes that will be in the new SelectedNodes collection.
	// Note: The Nodes collection exposed by the event args
	// is read-only.
	foreach ( UltraTreeNode node in e.NewSelections )
	{
		sb.Append( node.Key );
		sb.Append( ", " );
	}

	sb.Append(" Press ''OK'' or ''Cancel''.");

	DialogResult dr = MessageBox.Show( this,
					  sb.ToString(),
					  "Selected nodes changing",
					  MessageBoxButtons.OKCancel );

	if ( dr == DialogResult.Cancel )
		e.Cancel = true;
		
}
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