We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

adding columns programmatically treeview

how can I fill a treeview programmatically adding columns manually, i have this code.

For i As Integer = 0 To _Categorias.Count - 1
Dim newItem As TreeViewItemAdv = New TreeViewItemAdv
newItem.Header = _Categorias(i).Cai_nombre_completo
newItem.IsEditable = False
TreeViewAdv1.Items.Add(newItem)

For j As Integer = 0 To _Activos.Count - 1
If _Categorias(i).Cai_codigo = _Activos(j).cai_codigo Then
Dim newSubItem As TreeViewItemAdv = New TreeViewItemAdv
newSubItem.Header = _Activos(j).act_nombre_largo
newSubItem.IsEditable = False
newItem.Items.Add(newSubItem)
End If
Next
Next

but, i want more columns.

Thanks. :)

1 Reply

CS C. Sudha Syncfusion Team October 8, 2009 11:43 AM UTC

Hi Rafael,

Thanks for choosing Syncfusion products.

By setting MultiColumnEnable property to true, you can add the column to the treeview. The below code snippet will help you to add the header to the column:

[VB]

Dim TreeViewAdv1 As New TreeViewAdv()
TreeViewAdv1.MultiColumnEnable = True
TreeViewAdv1.ShowRootLines = True
TreeViewAdv1.ItemsSource = StudentInfo.CreateStudentList()
TreeViewAdv1.ItemTemplate = TryCast(Me.Resources("dataTemplate2"), HierarchicalDataTemplate)
TreeViewAdv1.ItemContainerStyle = TryCast(Me.Resources("TreeViewItemStyle2"), Style)


Dim c1 As New TreeViewColumn()
c1.DisplayMemberBinding = New Binding("RollNumber")
c1.Header = "Roll No."
c1.Width = 100
Dim c2 As New TreeViewColumn()
c2.DisplayMemberBinding = New Binding("FirstName")
c2.Header = "First Name"
c2.Width = 150
Dim c3 As New TreeViewColumn()
c3.DisplayMemberBinding = New Binding("LastName")
c3.Header = "Last Name"
c3.Width = 150

TreeViewAdv1.Columns = New TreeViewColumnCollection()
TreeViewAdv1.Columns.Add(c1)
TreeViewAdv1.Columns.Add(c2)
TreeViewAdv1.Columns.Add(c3)

treeborder.Child = TreeViewAdv1

For more information, Please download the attached sample.

Please let me know if you have any questions.

Regards,
SudhaC.



MultiColumnTreeView_17f7cf4f.zip

Loader.
Live Chat Icon For mobile
Up arrow icon