Treeview Control

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Treeview Control

Post by D Willett »

I have a treeview working recursively through a series of folders, the results being PDF documents in the last node.
I've put a PDF Viewer control on a form, how do I show the PDF selected from the treeview in the PDF control?

Here's my code for the treeview:

Code: Select all

' In general Declarations
   Dim tvn As Node

Private Sub Command1_Click()
   Me.MousePointer = vbHourglass

   TreeView1.Nodes.Clear
    
   ' Pathname to create folder/file list from
   p$ = App.Path
   MsgBox App.Path
   
   'p$ = Dir1.Path
   If Right$(p$, 1) <> "\" Then p$ = p$ + "\"
    
   Set tvn = TreeView1.Nodes.Add(, tvwParent, p$, p$)
    
   RecurseFiles2 p$
    
   Me.MousePointer = vbDefault
End Sub

Sub RecurseFiles2(ByVal fPath As String)
   Dim File_Name As String
   Dim File_Read As Integer         ' Number of Files Read
   Dim strTempPath As String
   Dim i As Integer

   If Right$(fPath, 1) <> "\" Then fPath = fPath & "\"
    
   ' to do a pattern match do, or something.
   ' folders won`t be included in the list (not my fault)
   ' File_Name = Dir$(fPath+"\*.exe", vbDirectory)
    
   File_Name = Dir$(fPath, vbDirectory)
   File_Read = 1

   Do While File_Name <> ""
       If File_Name <> "." And File_Name <> ".." Then
           strTempPath = fPath & File_Name
            
           If GetAttr(strTempPath) And vbDirectory Then
               Set tvn = TreeView1.Nodes.Add(fPath, tvwChild, strTempPath + "\", File_Name)
               RecurseFiles2 strTempPath    ' if a folder, then call this routine to scan that folder (recursion)
            
               File_Name = Dir$(fPath, vbDirectory)
               For i = 2 To File_Read
                   File_Name = Dir$
               Next
           Else
               Set tvn = TreeView1.Nodes.Add(fPath, tvwChild, strTempPath, File_Name)
           End If
       End If
        
       File_Name = Dir$
       File_Read = File_Read + 1
   Loop
End Sub


Cheers ...

Dave.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Treeview Control

Post by Rudi »

Hi Dave,

I'm way out of my depth here, but see if the feedback on either of these pages can give you some guidance:

1. Displaying a PDF in a control in Visual Basic
2. How To View Pdf File In Vb.Net
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Treeview Control

Post by D Willett »

Hi Rudi, cheers for the links.
Not quite what I was after but all the same very grateful.

It's capturing the path and filename from the last node in the treeview which I can't quite get around.

Kind Regards
Cheers ...

Dave.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Treeview Control

Post by Rudi »

Oops...I was under the impression that you were having issues with displaying the PDF in a control. :sorry:
I'll have to leave this to someone else as its out of my depth. Hopefully someone can assist before Hans returns on the weekend.

Cheers
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
Jan Karel Pieterse
Microsoft MVP
Posts: 656
Joined: 24 Jan 2010, 17:51
Status: Microsoft MVP
Location: Weert, The Netherlands

Re: Treeview Control

Post by Jan Karel Pieterse »

The treeview control has a nodeclick event you can use, which gives you the clicked node as an object in its argument list:

Code: Select all

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Msgbox "You clicked " & Node.Text
End Sub
Regards,

Jan Karel Pieterse
Excel MVP jkp-ads.com

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Treeview Control

Post by D Willett »

Hi Jan
Thanks for the post. I got around some of the problem by capturing the Root, Parent etc.
But I will use your code also:

Code: Select all

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)

If Me.TreeView1.SelectedItem.Children > 0 Then
Exit Sub
Else
MsgBox "You clicked " & Node.Text
End If

End Sub
Kind Regards
Cheers ...

Dave.

User avatar
Jan Karel Pieterse
Microsoft MVP
Posts: 656
Joined: 24 Jan 2010, 17:51
Status: Microsoft MVP
Location: Weert, The Netherlands

Re: Treeview Control

Post by Jan Karel Pieterse »

Regards,

Jan Karel Pieterse
Excel MVP jkp-ads.com

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Treeview Control

Post by D Willett »

Some great work there !!!
Does this work in VB6?
Cheers ...

Dave.

User avatar
Jan Karel Pieterse
Microsoft MVP
Posts: 656
Joined: 24 Jan 2010, 17:51
Status: Microsoft MVP
Location: Weert, The Netherlands

Re: Treeview Control

Post by Jan Karel Pieterse »

No need, if you use a treeview in VB6 you can make sure it is installed with your application. However, VB6 addins won't work on 64 bit Office. Period.
Regards,

Jan Karel Pieterse
Excel MVP jkp-ads.com