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
Private Sub ultraTree1_BeforeSelect(ByVal sender As System.Object, ByVal e As BeforeSelectEventArgs) Handles ultraTree1.BeforeSelect
' Iterate the members of the new selection and check
' the level of each node to determine which levels are
' included in the selection.
Dim selectedNodes As SelectedNodesCollection = e.NewSelections
Dim levels As New List(Of Integer)
Dim i As Integer
For i = 0 To selectedNodes.Count - 1
Dim node As UltraTreeNode = selectedNodes(i)
Dim level As Integer = node.Level
If levels.Contains(level) = False Then levels.Add(level)
Next
' If there are no root level nodes selected, allow descendants
' of collapsed nodes to be selected.
If (levels.Contains(0) = False) Then
e.IncludeCollapsedDescendantsOnRangeSelection = True
End If
End Sub