Version

BeforeExpand Event

Occurs before an UltraTreeNode is expanded.
Syntax
'Declaration
 
Public Event BeforeExpand As BeforeNodeChangedEventHandler
public event BeforeNodeChangedEventHandler BeforeExpand
Event Data

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

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
TreeNode The UltraTreeNode (read-only)
Remarks

The CancelableNodeEventArgs.TreeNode property of the CancelableNodeEventArgs contains a reference to UltraTreeNode that is being expanded.

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

When Override.ShowExpansionIndicator is set to CheckOnExpand, this event should be used to populate the child nodes of a particular UltraTreeNode. If this event is not cancelled, the UltraTree control will check to see if the node has children after this event completes. If the node has children, it will expand as normal. If it does, the expansion indicator will disappear.

Example
The following sample code illustrates some of the information available in the BeforeExpand 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_BeforeExpand(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinTree.CancelableNodeEventArgs) Handles ultraTree1.BeforeExpand

    ' Note: In order to load node collections on demand, set
    ' the appropriate Override object's 'ShowExpansionIndicator' 
    ' property to 'CheckOnExpand'. Then in this event place 
    ' logic to add the child nodes to the node being expanded 
    ' (e.g. with the e.TreeNode.Nodes's 'Add' or 'AddRange' methods).
    '
    ' In addition to its 'Tag' property the node exposes
    ' a 'DataKey' property (which is also opaque to the node).
    ' It is often useful with 'CheckOnDemand' to associate
    ' some identifier/key of a corresponding row in a dataset.
    '
    ' With 'CheckOnExpand' specified, if this event is called 
    ' and no child nodes are added then the expansion indicator
    ' will disappear and this event will not fire again. 
    '
    ' However, this can be reset by calling the UltraTree's 
    ' 'ResetExpansionIndicator' method to re-show the expansion
    ' indicator and re-fire this event when the user expands the
    ' node again.
    '
    ' Refer to the 'UltraTree Load On Demand VB' sample.

    Dim sb As New System.Text.StringBuilder()

    sb.Append("Node: ")
    sb.Append(e.TreeNode.Key)
    sb.Append(" is about to be expanded.")

    Debug.WriteLine(sb.ToString())

    ' Note : This action can be canceled by the following line of code.
    'e.Cancel = True

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

private void ultraTree1_BeforeExpand(object sender, Infragistics.Win.UltraWinTree.CancelableNodeEventArgs e)
{

	// Note: In order to load node collections on demand, set
	// the appropriate Override object's 'ShowExpansionIndicator' 
	// property to 'CheckOnExpand'. Then in this event place 
	// logic to add the child nodes to the node being expanded 
	// (e.g. with the e.TreeNode.Nodes's 'Add' or 'AddRange' methods).
	//
	// In addition to its 'Tag' property the node exposes
	// a 'DataKey' property (which is also opaque to the node).
	// It is often useful with 'CheckOnDemand' to associate
	// some identifier/key of a corresponding row in a dataset.
	//
	// With 'CheckOnExpand' specified, if this event is called 
	// and no child nodes are added then the expansion indicator
	// will disappear and this event will not fire again. 
	//
	// However, this can be reset by calling the UltraTree's 
	// 'ResetExpansionIndicator' method to re-show the expansion
	// indicator and re-fire this event when the user expands the
	// node again.
	//
	// Refer to the 'UltraTree Load On Demand CS' sample.
	
	System.Text.StringBuilder sb = new System.Text.StringBuilder();

	sb.Append("Node: ");
	sb.Append(e.TreeNode.Key);
	sb.Append(" is about to be expanded.");

	Debug.WriteLine( sb.ToString() );

	// Note : This action can be canceled by the following line of code.
	//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