| auteur : argyronet |
En récupérant l'index, vous pouvez repointer le noeud sur lequel vous avez ajouté un fils.
Par exemple, vous êtes sur un noeud, vous stockez son index, vous ajoutez le fils puis vous activez le noeud ainsi :
oTreeView. Nodes (intOriginalIndex). Selected = True
|
|
| auteur : Team Access |
Dim currentNode As MSComctlLib. node
Dim nbCheckedNodes As Integer
For Each currentNode In LeTreeViewDeTonFormulaire. Nodes
If currentNode. Checked Then
nbCheckedNodes = nbCheckedNodes + 1
End If
End Sub
|
Dans cette exemple nous nous contentons de compter le nombre de lignes sélectionnées. Vous pourrez donc facilement imaginer comment procéder à divers traitements sur les lignes qui vous intéressent.
|
| auteur : Tofalu |
Pour cela on peut utiliser une procédure récursive qui remonte l'arbre.
Cette procédure est la suivante :
Private Sub ChercheGeneration (oNode As Node, intGeneration As Integer)
If Not oNode. Parent Is Nothing Then
intGeneration = intGeneration + 1
ChercheGeneration oNode. Parent , intGeneration
End If
End Sub
|
Exemple d'utilisation sur l'évènement Double Clic du Treeview
Private Sub MonTreeView_DblClick ()
Dim Generation As Integer
ChercheGeneration MonTreeView. SelectedItem , Generation
MsgBox Generation
End Sub
|
Notons que la numérotation commence à zéro.
|
| auteur : argyronet | Ce code permet d'imprimer dans un état le même treeview de votre Formulaire.
Il faut impérativement faire référence à la librairie d'objet de VB6 (VB6.olb) car ce code utilise l'objet Printer
Option Compare Database
Option Explicit
Const COORDINATE_XY As Integer = 1440
Const TEXT_HEIGHT As Integer = 192
Const OFFSET_TORIGHT As Integer = 256
Const OFFSET_TODOWN As Integer = 128
Private Sub cmdPrint_Click ()
Dim oTreeView As TreeView
Set oTreeView = TreeViewMain. Object
Printer. CurrentX = COORDINATE_XY
Printer. CurrentY = COORDINATE_XY
PrintTreeView oTreeView , Printer, COORDINATE_XY
Printer. EndDoc
Set oTreeView = Nothing
MsgBox " Impression de l'arborescence terminée ! " , 64
End Sub
Private Sub PrintTreeView (ByVal TVWObject As TreeView, ByVal DevicePrinter As Object, DeviceCoordinates As Integer)
Dim oNode As Node
Set oNode = TVWObject. Nodes (1 )
Do Until oNode Is Nothing
DevicePrinter. CurrentX = DeviceCoordinates
PrintCurrentNode oNode, DevicePrinter
Set oNode = oNode. Next
Loop
Set oNode = Nothing
End Sub
Private Sub PrintCurrentNode (ByVal TVWNode As Node, ByVal DevicePrinter As Printer)
Dim sngNodeChildOffset As Single
Dim sngX1 As Single
Dim sngY1 As Single
Dim sngX2 As Single
Dim sngY2 As Single
Dim sngTreeLineHeight As Single
With DevicePrinter
sngNodeChildOffset = . CurrentX + OFFSET_TORIGHT
sngX1 = . CurrentX + OFFSET_TORIGHT / 2
sngTreeLineHeight = TEXT_HEIGHT + OFFSET_TODOWN
Printer. Print TVWNode. Text
sngY1 = DevicePrinter. CurrentY
End With
Set TVWNode = TVWNode. Child
Do Until TVWNode Is Nothing
sngX2 = DevicePrinter. CurrentY
sngY2 = sngX2 + sngTreeLineHeight / 2
DevicePrinter. Line (sngX1, sngY1)- (sngX1, sngY2)
DevicePrinter. Line - Step (OFFSET_TORIGHT / 2 , 0 )
DevicePrinter. CurrentY = sngX2
DevicePrinter. CurrentX = sngNodeChildOffset
PrintCurrentNode TVWNode, DevicePrinter
Set TVWNode = TVWNode. Next
Loop
End Sub
|
|
| auteur : =JBO= | Ci-joint un code permettant de piloter le clic droit dans un TreeView nommée TV
Private Sub TV_MouseDown (ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
If Button = vbKeyRButton Then
Set TV. DropHighlight = TV. HitTest (X, Y)
Else
Set TV. DropHighlight = Nothing
End If
End Sub
Private Sub TV_MouseMove (ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
Screen. MousePointer = 0
If Not (TV. DropHighlight Is Nothing ) And Button < > vbKeyRButton Then
Set TV. DropHighlight = Nothing
End If
End Sub
Private Sub TV_MouseUp (ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
Dim oNode As MSComctlLib. Node , p As Parametrage
If Button = vbKeyRButton Then
Set oNode = TV. HitTest (X, Y)
If Not (oNode Is Nothing ) Then
If Not (TV. DropHighlight Is Nothing ) Then
If oNode = TV. DropHighlight Then
. . .
End If
End If
End If
End If
Set TV. DropHighlight = Nothing
End Sub
|
|
Consultez les autres F.A.Q's
Les sources présentés sur cette pages sont libre de droits,
et vous pouvez les utiliser à votre convenance. Par contre cette page de présentation de ces sources constitue une oeuvre intellectuelle protégée par les droits d'auteurs.
Copyright ©2004
Developpez LLC. Tout droits réservés Developpez LLC.
Aucune reproduction, même partielle, ne peut être faite de ce site et de
l'ensemble de son contenu : textes, documents et images sans l'autorisation
expresse de Developpez LLC. Sinon vous encourez selon la loi jusqu'à 3 ans
de prison et jusqu'à 300 000 E de dommages et intérets.
Cette page est déposée à la SACD.
|