Hallo kann mir jemand sagen, wie man einen Treeview ausdrucken kann. Es wäre nicht notwendig die Icons mitauszudrucken, aber zumindest der gesamte Inhalt, also auch das was nicht gerade sichtbar ist, muß aufs papier.
Hallo,
habe mich Deinem Problem gewidmet, u.a. weil ichs vielleicht auch mal selber brauchen kann/werde. Folgendes ist dabei herausgekommen:
Dieses Coding unbedingt in eine VB-Klasse stellen: (ich nenne sie „clsTreeView“)
Option Explicit
DefBool B
DefInt I
DefInt F 'File-Handle
DefLng L
DefLng H 'Windows-Handle
DefCur C
DefDate D
DefStr S
DefObj O
DefVar V
'
Public Event TreeWalkNode(ByVal n As MSComctlLib.Node, blnCancel, ByVal intDeep)
'
Public Sub TreeWalk(ByVal n As MSComctlLib.Node, blnCancel, ByVal blnFromRoot, ByVal intDeep)
Dim lngMyErr
Dim strMyDescription
Dim strMySource
Dim strBuf
Dim objChild As MSComctlLib.Node
'
If blnCancel Then Exit Sub
On Error GoTo ErrorHandler
Set objChild = n.Child
intDeep = intDeep + 1
'
If blnFromRoot Then 'Verzeichnisse von Root in die Tiefe durchrattern
Do While Not objChild Is Nothing
If blnCancel Then Exit Do
RaiseEvent TreeWalkNode(objChild, blnCancel, intDeep)
If blnCancel Then Exit Do
Call Me.TreeWalk(objChild, blnCancel, blnFromRoot, intDeep)
Set objChild = objChild.Next
Loop
Else 'Verzeichnisse von der Tiefe nach Root durchrattern
Do While Not objChild Is Nothing
If blnCancel Then Exit Do
Call Me.TreeWalk(objChild, blnCancel, blnFromRoot, intDeep)
If blnCancel Then Exit Do
RaiseEvent TreeWalkNode(objChild, blnCancel, intDeep)
Set objChild = objChild.Next
Loop
End If
'
'--------------
ExitHandler:
On Error Resume Next
Set objChild = Nothing
If lngMyErr 0 Then
'Call MsgBox("Run-time error '" & lngMyErr & "':" & vbLf & vbLf & strMyDescription & vbLf & Space(100), vbSystemModal, "Microsoft Visual Basic")
On Error GoTo 0
Call Err.Raise(lngMyErr, strMySource, strMyDescription)
End If
On Error GoTo 0
Exit Sub
'
'--------------------
ErrorHandler:
lngMyErr = Err.Number
strMyDescription = Err.Description
strMySource = Err.Source
Resume ExitHandler
End Sub
Folgendes Coding ins Form:
Option Explicit
'damit empfängst Du Deine eigenen Events aus der Klasse
Private WithEvents Ct As clsTreeView
'
Private Sub Command1\_Click()
Dim n As MSComctlLib.Node
'
Set Ct = New clsTreeView
Set n = Me.TreeView1.Nodes(1)
Do
Call Ct\_TreeWalkNode(n, False, 0)
Call Ct.TreeWalk(n, False, True, 0)
Set n = n.Next
If n Is Nothing Then Exit Do
Loop
Set Ct = Nothing
End Sub
Jetzt bekommst Du ein Node nach dem anderen als Event zugeschickt (Coding ebenfalls ins Form stellen):
Private Sub Ct\_TreeWalkNode(ByVal n As MSComctlLib.Node, blnCancel As Boolean, ByVal intDeep As Integer)
Debug.Print Space$(intDeep \* 3) & n.text
End Sub
Weiters brauchst Du das TreeView-Control: TreeView1
und einen Command-Button: Command1
Das man hier mehr als nur Debug.Print machen kann, ist wohl klar!!!
greets from MichL (Vienna)
Noch was besseres gefunden … macht grafisch auch was her:
http://www.vb-helper.com/Howto/prnttrvw.zip
greets from MichL (Vienna)