Posted 17 February 2023, 4:27 am EST
Hi Folks,
Is there a way to bind list of items that, themselves can contain a list of items (and so on) to a C1Treeview. It would seem that this would be a natural type of binding for a C1Treeview, similar to the way a file system is set up where a folder can contain folders which can contain folders . . .
Here is a stripped down non bound example:
Imports C1.Win.TreeView
Public Class Form1
Private lData As New List(Of classData)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
loadData()
loadTreeView(C1TreeView1.Nodes, lData)
End Sub
Private Sub loadData()
Dim parent1 = New classData("Parent1")
Dim parent2 = New classData("Parent2")
Dim parent3 = New classData("Parent3")
Dim child1a = New classData("Child1a")
Dim child1b = New classData("Child1b")
Dim grandchild1b1 = New classData("Grandchild1b1")
parent1.children.Add(child1a)
parent1.children.Add(child1b)
child1b.children.Add(grandchild1b1)
lData.Add(parent1)
lData.Add(parent2)
lData.Add(parent3)
End Sub
Private Sub loadTreeView(nodes As C1TreeNodeCollection, l As List(Of classData))
For Each item In l
Dim node = New C1TreeNode(item)
nodes.Add(node)
loadTreeView(node.Nodes, item.children)
Next
End Sub
End Class
Public Class classData
Public Property title As String
Public Property children As New List(Of classData)
Public Sub New(title As String)
Me.title = title
End Sub
Public Overrides Function ToString() As String
Return title
End Function
End Class