Imports Infragistics.Win
Imports Infragistics.Win.Layout
Imports Infragistics.Win.UltraWinTree
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Dim dataTable As DataTable = Me.GetData()
' Set the ViewStyle property to 'Grid'
Me.ultraTree1.ViewStyle = ViewStyle.Grid
' Add a column for each DataColumn in the DataTable to the RootColumnSet's
' Columns collection, using the DataColumn's 'ColumnName' property as the
' key for the corresponding UltraTreeNodeColumn.
Dim rootColumnSet As UltraTreeColumnSet = Me.ultraTree1.ColumnSettings.RootColumnSet
Dim dataColumn As DataColumn
For Each dataColumn In dataTable.Columns
Dim column As UltraTreeNodeColumn = rootColumnSet.Columns.Add(dataColumn.ColumnName)
' Store a reference to the underlying DataColumn in the Tag property.
column.Tag = dataColumn
' Set AllowMoving to 'AllowAll', so that the end user
' can drag the column to a different location.
column.AllowMoving = GridBagLayoutAllowMoving.AllowAll
' Set AllowSorting to True, so that the end user
' can sort the nodes collections associated with
' this column by clicking on its header.
column.AllowSorting = DefaultableBoolean.True
' Set AutoSizeMode to 'VisibleNodes', so that the end user
' can auto-size the column by double-clicking on the right
' edge of its header.
column.AutoSizeMode = ColumnAutoSizeMode.VisibleNodes
' Set CanShowExpansionIndicator to True for the string columns,
' so that cells in the column can show the expansion indicator
' when the ViewStyle is 'OutlookExpress'.
If dataColumn.DataType Is GetType(String) Then
column.CanShowExpansionIndicator = DefaultableBoolean.True
Else
column.CanShowExpansionIndicator = DefaultableBoolean.False
End If
' Use the column's CellAppearance to change the color of
' the text displayed by the cells in the 'CompanyName' column.
If column.Key = "CompanyName" Then
column.CellAppearance.BackColor = Color.LightBlue
column.CellAppearance.BackColor2 = Color.CornflowerBlue
column.CellAppearance.BackGradientStyle = GradientStyle.Horizontal
column.CellAppearance.ForeColor = Color.DarkBlue
End If
' Set CellWrapText to False to prevent text from
' wrapping to additional lines.
column.CellWrapText = DefaultableBoolean.False
' Set the DataType property to the DataType of the associated DataColumn
column.DataType = dataColumn.DataType
' Use an EditorWithText embeddable editor to render the cell data
column.Editor = New EditorWithText()
' Format the 'RecordID' column
If column.Key = "RecordID" Then
column.Format = "00000"
End If
' Assign the current culture to the FormatProvider property.
column.FormatProvider = System.Globalization.CultureInfo.CurrentCulture
' Set the ForeColor property of the HeaderAppearance
column.HeaderAppearance.ForeColor = SystemColors.ControlDark
' Set the NullText property to "[NULL]"
column.NullText = "[NULL]"
' Show sort indicators for all columns
column.ShowSortIndicators = DefaultableBoolean.True
' Sort the 'CompanyName' column in ascending order
If column.Key = "CompanyName" Then
column.SortType = SortType.Ascending
End If
' Set the Text property of the 'CompanyName' column
If column.Key = "CompanyName" Then
column.Text = "Company Name"
End If
Next
' Hide the 'CustomerID' column
rootColumnSet.Columns("CustomerID").Visible = False
' Add a node for each DataRow in the table
Dim row As DataRow
For Each row In dataTable.Rows
Dim nodeKey As String = row("CustomerID")
Dim node As UltraTreeNode = Me.ultraTree1.Nodes.Add(nodeKey)
For Each dataColumn In dataTable.Columns
Dim val As Object = row(dataColumn.ColumnName)
node.SetCellValue(rootColumnSet.Columns(dataColumn.ColumnName), val)
Next
Next
End Sub
Private Function GetData() As DataTable
' Create a DataTable
Dim dataTable As DataTable = New DataTable()
' Add some columns
dataTable.Columns.Add("RecordID", GetType(Integer))
dataTable.Columns.Add("CustomerID", GetType(String))
dataTable.Columns.Add("CompanyName", GetType(String))
dataTable.Columns.Add("ContactName", GetType(String))
dataTable.Columns.Add("ContactTitle", GetType(String))
' Add some rows
dataTable.Rows.Add(New Object() {1652, "ALFKI", "Alfreds Futterkiste", "Maria Anders", "Sales Representative"})
dataTable.Rows.Add(New Object() {1346, "ANATR", "Ana Trujillo Emparedados y helados", "Ana Trujillo", "Owner"})
dataTable.Rows.Add(New Object() {127, "ANTON", "Antonio Moreno Taquería", "Antonio Moreno", "Owner"})
dataTable.Rows.Add(New Object() {4460, "AROUT", "Around the Horn", "Thomas Hardy", "Sales Representative"})
dataTable.Rows.Add(New Object() {166, "BERGS", "Berglunds snabbköp", "Christina Berglund", "Order Administrator"})
Return dataTable
End Function