Determines whether
UltraTreeNode instances which belong to different
Nodes collections can be concurrently selected.
The following code sample demonstrates how to use the UltraTree's SelectionBehavior property to allow a selection to contain nodes from different collections, while restricting the selection to nodes that belong to the last level of the tree:
Imports System.Collections.Generic
Imports Infragistics.Win
Imports Infragistics.Win.Misc.UltraWinTree
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Set the SelectionBehavior property to 'ExtendedAcrossCollections'
' to allow nodes from different collections to be selected concurrently.
Me.ultraTree1.SelectionBehavior = SelectionBehavior.ExtendedAcrossCollections
' Add nodes to the tree
Me.PopulateTree(Me.ultraTree1)
' Determine the deepest level
Dim deepestLevel As Integer = Me.GetDeepestLevel(Me.ultraTree1)
' Only allow selection of leaf nodes
Me.AllowSelectionOnLevel(Me.ultraTree1, deepestLevel)
End Sub
Private Sub PopulateTree(ByVal treeControl As UltraTree)
Try
treeControl.BeginUpdate()
treeControl.Nodes.Clear()
Dim i As Integer
For i = 0 To 2
Dim text As String = String.Format("Root {0}", i)
Dim rootNode As UltraTreeNode = treeControl.Nodes.Add(Nothing, text)
Me.PopulateNodes(rootNode.Nodes, 1)
Next
Finally
treeControl.EndUpdate()
End Try
treeControl.ExpandAll()
End Sub
Private Sub PopulateNodes(ByVal nodesCollection As TreeNodesCollection, ByVal level As Integer)
If (level > 3) Then Return
Dim parentNode As UltraTreeNode = nodesCollection.ParentNode
Dim i As Integer
For i = 0 To 2
Dim text As String = String.Format("{0}\Node {1}", parentNode.Text, i)
Dim node As UltraTreeNode = nodesCollection.Add(Nothing, text)
If (level < 3) Then
Me.PopulateNodes(node.Nodes, level + 1)
End If
Next
End Sub
Public Sub AllowSelectionOnLevel(ByVal tree As UltraTree, ByVal level As Integer)
Dim levels As New List(Of Integer)
levels.Add(level)
Me.AllowSelectionOnLevels(tree, levels)
End Sub
Public Sub AllowSelectionOnLevels(ByVal tree As UltraTree, ByVal levels As List(Of Integer))
Dim deepestLevel As Integer = Me.GetDeepestLevel(tree)
Dim i As Integer
For i = 0 To deepestLevel
tree.NodeLevelOverrides(i).ResetSelectionType()
If (levels.Contains(i)) Then Continue For
tree.NodeLevelOverrides(i).SelectionType = SelectType.None
Next
End Sub
Public Function GetDeepestLevel(ByVal tree As UltraTree) As Integer
Dim deepestLevel As Integer = 0
Me.GetDeepestLevel(tree.Nodes, deepestLevel)
Return deepestLevel
End Function
Private Sub GetDeepestLevel(ByVal nodes As TreeNodesCollection, ByRef deepestLevel As Integer)
Dim i As Integer
For i = 0 To nodes.Count - 1
Dim node As UltraTreeNode = nodes(i)
If (i = 0) Then deepestLevel = Math.Max(deepestLevel, node.Level)
If (node.HasNodes) Then Me.GetDeepestLevel(node.Nodes, deepestLevel)
Next
End Sub
using System.Collections.Generic;
using Infragistics.Win;
using Infragistics.Win.Misc.UltraWinTree;
private void Form1_Load(object sender, EventArgs e)
{
// Set the SelectionBehavior property to 'ExtendedAcrossCollections'
// to allow nodes from different collections to be selected concurrently.
this.ultraTree1.SelectionBehavior = SelectionBehavior.ExtendedAcrossCollections;
// Add nodes to the tree
this.PopulateTree( this.ultraTree1 );
// Determine the deepest level
int deepestLevel = this.GetDeepestLevel( this.ultraTree1 );
// Only allow selection of leaf nodes
this.AllowSelectionOnLevel( this.ultraTree1, deepestLevel);
}
private void PopulateTree( UltraTree treeControl )
{
try
{
treeControl.BeginUpdate();
treeControl.Nodes.Clear();
for ( int i = 0; i < 3; i ++ )
{
string text = string.Format( "Root {0}", i );
UltraTreeNode rootNode = treeControl.Nodes.Add( null, text );
this.PopulateNodes( rootNode.Nodes, 1 );
}
}
finally
{
treeControl.EndUpdate();
}
this.ultraTree1.ExpandAll();
}
private void PopulateNodes( TreeNodesCollection nodesCollection, int level )
{
if ( level > 3 )
return;
UltraTreeNode parentNode = nodesCollection.ParentNode;
for ( int i = 0; i < 3; i ++ )
{
string text = string.Format( @"{0}\Node {1}", parentNode.Text, i );
UltraTreeNode node = nodesCollection.Add( null, text );
if ( level < 3 )
this.PopulateNodes( node.Nodes, level + 1 );
}
}
public void AllowSelectionOnLevel( UltraTree tree, int level )
{
List<int> levels = new List<int>(1);
levels.Add( level );
this.AllowSelectionOnLevels( tree, levels );
}
public void AllowSelectionOnLevels( UltraTree tree, List<int> levels )
{
int deepestLevel = this.GetDeepestLevel( tree );
for ( int i = 0; i <= deepestLevel; i ++ )
{
tree.NodeLevelOverrides[i].ResetSelectionType();
if ( levels.Contains(i) )
continue;
tree.NodeLevelOverrides[i].SelectionType = SelectType.None;
}
}
public int GetDeepestLevel( UltraTree tree )
{
int deepestLevel = 0;
this.GetDeepestLevel( tree.Nodes, ref deepestLevel );
return deepestLevel;
}
private void GetDeepestLevel( TreeNodesCollection nodes, ref int deepestLevel )
{
for ( int i = 0; i < nodes.Count; i ++ )
{
UltraTreeNode node = nodes[i];
if ( i == 0 )
deepestLevel = Math.Max( deepestLevel, node.Level );
if ( node.HasNodes )
this.GetDeepestLevel( node.Nodes, ref deepestLevel );
}
}
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