4 Answers, 1 is accepted
To check for existence of child nodes you can use the myParentNode.Nodes.Count property.
Then you can set the Visible property of the node to True or False.
Regards,
Veselin Vasilev
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
my code (GenerateTreeview)
Protected Sub GenerateTreview()
Dim dbconn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\gestione_aule.mdf;Integrated Security=True;User Instance=True")
dbconn.Open()
Dim tb As New DataSet()
Dim campusTabelle As New DataTable()
Dim palazziTabella As New DataTable()
Dim auleTabella As New DataTable()
Dim campusAdapter As New SqlDataAdapter("SELECT * FROM Campus", dbconn)
Dim palazziadapter As New SqlDataAdapter("SELECT * FROM Palazzi", dbconn)
Dim auleadapter As New SqlDataAdapter("SELECT * FROM Aule", dbconn)
campusAdapter.Fill(campusTabelle)
palazziadapter.Fill(palazziTabella)
auleadapter.Fill(auleTabella)
tb.Tables.Add(campusTabelle)
tb.Tables.Add(palazziTabella)
tb.Tables.Add(auleTabella)
tb.Relations.Add(
"CampusPalazzi", tb.Tables(0).Columns("ID_Campus"), tb.Tables(1).Columns("ID_Campus"))
tb.Relations.Add(
"PalazziAule", tb.Tables(1).Columns("ID_Palazzo"), tb.Tables(2).Columns("ID_Palazzo"))
Dim campusRighe As DataRow
For Each campusRighe In tb.Tables(0).Rows
Dim CampusNodi As New RadTreeNode(campusRighe("Nome").ToString())
RdTreeViewAule.Nodes.Add(CampusNodi)
Dim palazzoRighe As DataRow
For Each palazzoRighe In campusRighe.GetChildRows("CampusPalazzi")
Dim PalazziNodi As New RadTreeNode(palazzoRighe("Nome").ToString())
CampusNodi.Nodes.Add(PalazziNodi)
Dim auleRighe As DataRow
For Each auleRighe In palazzoRighe.GetChildRows("PalazziAule")
If RdTreeViewAule.Nodes.Count > 0 Then
Dim auleNodi As New RadTreeNode(auleRighe("Nome").ToString(), auleRighe("id_aula"))
PalazziNodi.Nodes.Add(auleNodi)
Else
RdTreeViewAule.SelectedNode.ParentNode.Visible = False
End If
Next auleRighe
Next palazzoRighe
Next campusRighe
RdTreeViewAule.ExpandAllNodes()
End Sub
You need to check if the GetChildRows array has items.
For example you need to ensure that palazzoRighe.GetChildRows("PalazziAule") length is greater than zero.
Kind regards,
Veselin Vasilev
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.