Zeusmax
Member
- Joined
- Oct 10, 2023
- Messages
- 7
- Programming Experience
- 10+
Greetings,
I have a problem with a treeview,
up to 2 levels it works fine, the third level gives index error, can you help me
my tabel : ID_Livello_padre, ID_Livello_figlio, descrizione
I have a problem with a treeview,
up to 2 levels it works fine, the third level gives index error, can you help me
my tabel : ID_Livello_padre, ID_Livello_figlio, descrizione
VB.NET:
Private Sub Form9_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim mtable2 As New DataTable
mtable2 = MyDBaseM.Table("SELECT * FROM livelli")
TreeView1.Nodes.Clear()
'add i primi livelli
For Each dr As DataRow In mtable2.Rows
If dr.Item("ID_Livello_padre").Equals(0) Then
TreeView1.Nodes.Add(dr.Item("descrizione"))
End If
Next
'add i secondi livelli
Dim child As Integer = 0
Dim grandchild As Integer = 0
For Each dr2 As DataRow In mtable2.Rows
For Each dr2Child As DataRow In mtable2.Select("ID_Livello_Padre='" & dr2.Item("ID_Livello_figlio") & "'")
If child < TreeView1.Nodes.Count - 1 Then
TreeView1.Nodes(child).Nodes.Add(dr2Child.Item("descrizione"))
End If
' add i terzi livelli
For Each dr2GrandChild As DataRow In mtable2.Select("ID_Livello_Padre='" & dr2Child.Item("ID_Livello_figlio") & "'")
TreeView1.Nodes(child).Nodes(grandchild).Nodes.Add(dr2GrandChild.Item("descrizione"))
Next
grandchild = grandchild + 1
Next
child = child + 1
Next
End Sub
Last edited by a moderator: