This is a migrated thread and some comments may be shown as answers.

Treeview hide parentNode

4 Answers 96 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rubihno
Top achievements
Rank 1
Rubihno asked on 07 Oct 2008, 11:11 AM
Hi, I have a treeview populate to sql tables, what is the problem.., how i make to hide a parentnode if the parent don't have a node?Programmatically?

I have used the example code - sql data table for populate my treeview



4 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 07 Oct 2008, 12:01 PM
Hello Rubihno,

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.
0
Rubihno
Top achievements
Rank 1
answered on 07 Oct 2008, 12:54 PM

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

 

0
Rubihno
Top achievements
Rank 1
answered on 08 Oct 2008, 08:26 AM
in my example code how i make to hide a parentnode if don'have a node?
0
Veselin Vasilev
Telerik team
answered on 10 Oct 2008, 09:02 AM
Hi Rubihno,

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.
Tags
TreeView
Asked by
Rubihno
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Rubihno
Top achievements
Rank 1
Share this question
or