Treeview hide parentNode

5 posts, 0 answers
  1. Rubihno
    Rubihno avatar
    86 posts
    Member since:
    Jun 2008

    Posted 07 Oct 2008 Link to this post

    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



  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 07 Oct 2008 Link to this post

    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.
  3. Rubihno
    Rubihno avatar
    86 posts
    Member since:
    Jun 2008

    Posted 07 Oct 2008 Link to this post

    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

     

  4. Rubihno
    Rubihno avatar
    86 posts
    Member since:
    Jun 2008

    Posted 08 Oct 2008 Link to this post

    in my example code how i make to hide a parentnode if don'have a node?
  5. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 10 Oct 2008 Link to this post

    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.
Back to Top