Treeview noeud enfant vba

nina71287

XLDnaute Occasionnel
bonsoir,

j'aimerais récupérer les parents d'un nœud enfant j'ai essayé d'adapter ce code mais je n'y arrive pas

Dim intChild As Integer, i As Integer

For i = 1 To monarbre.Nodes.Count

intChild = Val(monarbre.Nodes.Item(i).Children)

If intChild > 0 Then MsgBox monarbre.Nodes.Item(i).Text & " " & LTrim(Str(intChild))
Next
je sais qu'avec parent on peut recuperer mais on recupere que le premier parent sachant qu'un noeud peut avoir plusieur niveaux

merci pour votre aide

bonne soirée
 

nina71287

XLDnaute Occasionnel
Re : Treeview noeud enfant vba

Bonjour,

je reviens vers vous pour un autre soucis que je rencontre avec mon treeview, je suis parti du code de jacques pour créer mon treeview et je l'ai modifié pour que s'affiche un arbre par projets. j'utilise la feuille arbre pour copier que les données du projet sélectionné dans ma listebox. Je rencontre un soucis avec le projet 4 il manque mes nœuds D2-10 à D2-12 pourtant ils sont bien recopier dans ma feuille arbre et font bien partie de mon "BDprogramme" qui me sert a afficher mon treeview hors ils ne s'affiche pas je ne sais pas si j'ai été claire (ps: il y avait surement une maniere plus simple de décomposer mon treeview par projets mais je ne mi connait pas très bien) merci pour votre aide ci joint mon fichier
 

Bebere

XLDnaute Barbatruc
Re : Treeview noeud enfant vba

bonjour Nina
ajout de la ligne debug.print,tu verras que i s'arrête à 57
Sub vpersonnes(Parent)
' procédure récursive
10 For i = 2 To UBound(base) ' + 3
20 k = Len(base(i, 1))
30 If k = 1 Then temp = "0" Else temp = Left(base(i, 1), k - 2)
40 If temp = "" Then temp = "0"
50 If temp = Parent Then
Debug.Print i & "," & base(i, 1) & "," & base(i, 2)
60 tw.Nodes.Add("NoeudMat" & Parent, tvwChild, "NoeudMat" & _
base(i, 1), base(i, 2)).Expanded = True
70 vpersonnes base(i, 1)
80 End If
90 Next i
End Sub

Private Sub userform_initialize()
10 Application.ScreenUpdating = False
With ThisWorkbook.Sheets("programmes activités")
20 For i = 2 To .Range("A65536").End(xlUp).Row
30 If Left(.Range("B" & i), 6) = "projet" Then
40 Me.ListBox2.AddItem .Range("B" & i).Value
50 End If
210 Next i
End With
1390 'ThisWorkbook.Sheets("programmes activités").Visible = False
1400 Application.ScreenUpdating = True
End Sub

à bientôt
 

nina71287

XLDnaute Occasionnel
Re : Treeview noeud enfant vba

merci pr ta reponse j'avais aussi remarque que i valait 57 et ma base filtré pour le projet 4 va jusqu'à 58 mais j'ai regardé pour les autres projets et ca fait la meme chose tout en m'affichant tout non?je ne comprend pas pourquoi il affiche que jusqu'a 55? merci pour ton aide
 

Bebere

XLDnaute Barbatruc
Re : Treeview noeud enfant vba

bonjour Nina
si j'ai le temps essayer avec 3 colonnes fils, pere,ce qui s'affiche
c'est peut être dans la structure,je connais pas trop treeview
si ce code t'intéresse
Private Sub userform_initialize()
10 Application.ScreenUpdating = False
Me.ListBox2.ColumnCount = 3
Me.ListBox2.ColumnWidths = "60;30;30"'tu mets 0 pour cacher
With ThisWorkbook.Sheets("programmes activités")
20 For i = 2 To .Range("A65536").End(xlUp).Row
30 If Left(.Range("B" & i), 6) = "projet" Then
Me.ListBox2.AddItem .Range("B" & i).Value
j = j + 1
Select Case j
Case 1
Me.ListBox2.List(0, 1) = i 'debut
Case 2
Me.ListBox2.List(1, 1) = i
Me.ListBox2.List(0, 2) = i - 1 'fin
Case 3
Me.ListBox2.List(2, 1) = i
Me.ListBox2.List(1, 2) = i - 1 'fin
Case 4
Me.ListBox2.List(3, 1) = i
Me.ListBox2.List(2, 2) = i - 1 'fin
Case 5
Me.ListBox2.List(4, 1) = i
Me.ListBox2.List(3, 2) = i - 1 'fin
Case 6
Me.ListBox2.List(5, 1) = i
Me.ListBox2.List(4, 2) = i - 1 'fin
Me.ListBox2.List(5, 2) = Sheets("programmes activités").Range("A65536").End(xlUp).Row
End Select
End If
210 Next i
End With
1390 'ThisWorkbook.Sheets("programmes activités").Visible = False
1400 Application.ScreenUpdating = True
End Sub

Private Sub listbox2_Click()
10 Me.monarbre.Nodes.Clear
20 Sheets("arbre").Cells.Clear
30 ActiveWorkbook.Names("BDprogramme").Delete
40 Titre = Me.ListBox2.Value
ld = Me.ListBox2.List(Me.ListBox2.ListIndex, 1): lf = Me.ListBox2.List(Me.ListBox2.ListIndex, 2)
Sheets("programmes activités").Range("A1:B2").Copy Destination:=Sheets("arbre").Range("A1")
Sheets("programmes activités").Range("A" & ld & ":B" & lf).Copy Destination:=Sheets("arbre").Range("A3")
With ThisWorkbook.Sheets("arbre")
320 k = .Range("A65536").End(xlUp).Row
340 .Range("A2:B" & k).Name = "BDprogramme"
End With
pere = "0"
nomPere = Application.VLookup(pere, [BDprogramme], 2, False)
'Application.VLookup(pere, [BDprogramme], 2, False)
370 Set tw = Me.monarbre
n = [BDprogramme].Rows.Count
390 base = [BDprogramme]
'tw.Nodes.Add(noeud_père,twchild,création_noeud_courant,libellé_noeud)
tw.Nodes.Add(, , "NoeudMat" & pere, nomPere).Expanded = True ' Racine arbre
' For i = 2 To n
'
' Next
vpersonnes pere

420 For Each TVNode In tw.Nodes
430 TVNode.ForeColor = vbBlack
440 Next
End Sub
 

kjin

XLDnaute Barbatruc
Re : Treeview noeud enfant vba

Bonsoir,
Je ne suis pas trop attardé sur ton code...
Je te laisse réadapter
A+
kjin
 

Pièces jointes

  • nina.zip
    24.7 KB · Affichages: 114
  • nina.zip
    24.7 KB · Affichages: 122
  • nina.zip
    24.7 KB · Affichages: 126

kjin

XLDnaute Barbatruc
Re : Treeview noeud enfant vba

Bonsoir,
Autre version incluant la liste des noeuds parents (je n'avais pas lu la demande initiale) si j'ai bien compris
J'ai ajouté le point au niveau initial pour le filtre dans la cas où le nb de projet atteint 10
A+
kjin
 

Pièces jointes

  • nina-v2.zip
    36 KB · Affichages: 143

Statistiques des forums

Discussions
312 298
Messages
2 086 975
Membres
103 416
dernier inscrit
SEB28110