Bonjour a tous.
Je développe sur Vb 2008 et SQL 2005.
J'ai arrivé à créer un TreeNode pour mon application avec Parent et ses fils donc sur 2 niveaux.
j'ai une table Tag, et Tag_ParentTag cette dernière possède la relation père-enfant.

Tag
IdTag------------NomTag
1 ------------Pays
2 ------------France
3 ------------Lyon
.
.
.

dans la table Tag_ParentTag

RefTag------------RefParentTag
2 -----------1
3 -----------2
.
.
.
donc ma node doit s'afficher comme ca:
+Pays
+France
-Lyon

je voudrais obtenir tous les fils d'un parent, et les sous-fils de ce fils et les sous-sous fils de ce sous-fils...etc
Merci beaucoup de votre aide je l'en ai besoin.

Voila mon code qui me permet juste d'obtenir le parent et ces fils c-a-d 2 niveaux :
+Pays
-France
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
 
 Dim cmd As New SqlCommand("SELECT distinct Tag.NomTag,Tag_ParentTag.RefParentTag  FROM Tag_ParentTag, Tag WHERE Tag_ParentTag.RefParentTag NOT IN (SELECT RefTag FROM Tag_ParentTag)and Tag_ParentTag.RefParentTag=Tag.IdTag ", con)
        con.Open()
        Dim Mycommand As SqlCommand = con.CreateCommand()
        Dim rRoot As SqlDataReader = cmd.ExecuteReader()
        Do While rRoot.Read()
            Me.TreeView1.Nodes.Add(rRoot.Item(0))
 
        Loop
        rRoot.Close()
        con.Close()
        For j = 0 To GetData(cmd).Rows.Count - 1
            Dim cmde1 As New SqlCommand("SELECT RefTag FROM Tag_ParentTag WHERE RefParentTag='" & GetData(cmd).Rows(j).Item(1) & "'", con)
 
            For k = 0 To GetData(cmde1).Rows.Count - 1
                Dim rqSql_Nod1 As String = "select NomTag from Tag where IdTag=any (select RefTag from Tag_ParentTag where  RefTag='" & GetData(cmde1).Rows(k).Item(0) & "')"
 
                Dim NewCmd As New SqlCommand(rqSql_Nod1, con)
                Mycommand.CommandText = rqSql_Nod1
 
                For i As Integer = 0 To GetData(NewCmd).Rows.Count - 1
                    Me.TreeView1.Nodes.Item(j).Nodes.Add(GetData(NewCmd).Rows(i).Item(0))
 
 
                Next
            Next
        Next