| 12
 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
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 
 |  
Private Sub BindClassement()
 
        'Efface ancien arbre
        treeClassment.Controls.Clear()
        treeClassment.EnableViewState = True
        Dim Root As New TreeNode
 
        Root.Text = "Tous les classements"
        Root.Value = "-1|-1|-1"
        Root.Expanded = True
 
        For Each r In dtvClassement
            Dim TreeNodeKeyFormat As String = "{0}|{1}|{2}"
            Dim NoeudParent As TreeNode = Nothing
 
 
            Dim Key As String = String.Format(TreeNodeKeyFormat, r.FAM.ToString, r.SFAM.ToString, r.SSFAM.ToString)
 
            Dim NouveauNoeud As New TreeNode
            NouveauNoeud.Text = r.Libelle
            NouveauNoeud.Value = Key
            NouveauNoeud.Expanded = False
 
            Dim TreeNodeParentKey As String
 
            If r.SSFAM <> -1 Then
                TreeNodeParentKey = String.Format(TreeNodeKeyFormat, r.FAM.ToString, r.SFAM.ToString, "-1")
            ElseIf r.SFAM <> -1 Then
                TreeNodeParentKey = String.Format(TreeNodeKeyFormat, r.FAM.ToString, "-1", "-1")
                NouveauNoeud.Expanded = True
            ElseIf r.FAM <> -1 Then
                TreeNodeParentKey = String.Format(TreeNodeKeyFormat, "-1", "-1", "-1")
            Else
                TreeNodeParentKey = ""
            End If
 
            If TreeNodeParentKey <> "" Then
                NoeudParent = FindNode(TreeNodeParentKey, Root)
                If NoeudParent IsNot Nothing Then
                    NoeudParent.ChildNodes.Add(NouveauNoeud)
                End If
            End If
 
 
 
        Next
 
        treeClassment.Nodes.Add(Root)
 
 
    End Sub
 
    ''' <summary>
    ''' Trouve le noeud d'un treeview en fonction de la cle FAM|SFAM
    ''' </summary>
    ''' <param name="key">La clé à rechercher dans le treeview</param>
    ''' <param name="root">le noeud du treeview à partir duquel la recherche est initiée</param>
    ''' <returns>Le noeud correspondant à la clé si il existe, sinon nothing</returns>
    ''' <remarks>Besoin de regarder que les noeuds de 1er rang</remarks>
    Private Shared Function FindNode(ByVal key As String, ByVal root As TreeNode) As TreeNode
 
        Dim n As TreeNode
        If root.Value = key Then
            Return root
            Exit Function
        Else
            For Each n In root.ChildNodes
                If n.Value = key Then
                    Return n
                    Exit Function
                Else
                    For Each ch In n.ChildNodes
                        If ch.Value = key Then
                            Return ch
                            Exit Function
                        End If
                    Next
                End If
            Next
        End If
 
        Return Nothing
    End Function
 
    Protected Sub treeClassment_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles treeClassment.SelectedNodeChanged
 
        'Mise en mémoire du dernier noeud sélectionné
        Dim DernierNoeudOuvert As String = treeClassment.SelectedValue
        ...
 
    End Sub | 
Partager