Solved

VB5: TreeView / ListView / ImageList

Posted on 1998-04-18
4
643 Views
Last Modified: 2008-03-17
I'm looking for a good sample app that shows how to use TreeView, ListView, and Image View to create your own custom file/dir list box.  The example should utilize every feature of these controls so I see exactly how everything works.  Either post the code here, e-mail it to me at ChrisK@yankton.com, or point to a web site that has the example I seek.  Thanks...
0
Comment
Question by:ChrisK
  • 2
4 Comments
 

Expert Comment

by:tlw2651
Comment Utility
This piece of code comes from the Enterprise edition Books Online.  I found it helpful... It works with the Biblio.mdb sample database that comes with VB 5.0


' General Declarations
Private mDbBiblio As Database ' Database variable.

Private Sub Form_Load()
      ' Open the Biblio.mdb and set the object variable
      ' to the database.
      Set mDbBiblio = DBEngine.Workspaces(0). _
      OpenDatabase("Biblio.mdb")

      ' Code to populate the TreeView control
      ' isn't shown here.
End Sub

Private Sub tvwDB_NodeClick(ByVal Node As Node)
      ' Check the Tag for "Publisher." If so, then
      ' call the MakeColumns procedure and then the
      ' GetTitles function.
      If Node.Tag = "Publisher" Then
            MakeColumns
            GetTitles Val(Node.Key)
      End If
End Sub

Private Sub MakeColumns()
      ' Clear the ColumnHeaders collection.
      lvwDB.ColumnHeaders.Clear
      ' Add four ColumnHeaders.
      lvwDB.ColumnHeaders.Add , , "Title", 2000
      lvwDB.ColumnHeaders.Add , , "Author"
      lvwDB.ColumnHeaders.Add , , "Year", 350
      lvwDB.ColumnHeaders.Add , , "ISBN"
End Sub

Private Sub GetTitles(PubID)
' Clear the old titles.
lvwDB.ListItems.Clear
' Declare object variable of type Recordset.
Dim rsTitles As Recordset
' While on this record, create a recordset using a
' query that finds only titles that have the same
' PubID. For each record in this recordset, add a
' ListItem object to the ListView control, and set
' the new object's properties with the record's
' Title, ISBN, and Author fields.
Set rsTitles = mDbBiblio.OpenRecordset _
("select * from Titles where PubID = " & PubID)

Do Until rsTitles.EOF
' Add ListItem.
            Set mItem = lvwDB.ListItems.Add()
            mItem.Text = rsTitles!TITLE
            mItem.SmallIcon = "smlBook"
            mItem.Icon = "book"      
            mItem.Key = rsTitles!ISBN
            ' Use a function to get the author and set
            ' the SubItems(1) property.
            mItem.SubItems(1) = GetAuthor(rsTitles!ISBN)
            If Not IsNull(rsTitles![Year Published]) Then
                  mItem.SubItems(2) =  _
            rsTitles![Year Published]
            End If
            mItem.SubItems(3) = rsTitles!ISBN
            rsTitles.MoveNext
Loop
End Sub

Private Function GetAuthor(ISBN)
      ' Declare DAO object variables.
      Dim rsTitleAuthor As Recordset
      Dim rsAuthors As Recordset    
      ' Set object variables to recordsets.
      Set rsTitleAuthor = mDbBiblio. _
      OpenRecordset("Title Author", dbOpenDynaset)
      Set rsAuthors = mDbBiblio. _
      OpenRecordset("Authors", dbOpenDynaset)
      ' Create query string.
      Dim strQuery As String
      strQuery = "ISBN = " & "'" & ISBN & "'"
      rsTitleAuthor.FindFirst strQuery
      ' If there is no author, return "n/a."
      ' Otherwise, return the name of the author.

      If rsTitleAuthor.NoMatch Then
            GetAuthor = "n/a"
            Exit Function
      Else
            ' Presume we have found the right recordset.
            ' Then reset the string query with Au_ID
            ' field value and search "Authors" table.
            strQuery = "Au_ID = " & rsTitleAuthor!AU_ID
            rsAuthors.FindFirst strQuery
            ' Return the name of the author from the Author
            ' field.
            GetAuthor = rsAuthors!Author
      End If
End Function
      

0
 
LVL 2

Author Comment

by:ChrisK
Comment Utility
I've got biblio.mdb and tried setting up the forms but it's not working.  Please send me this example in a vb form/project via e-mail.  Send to ChrisK@yankton.com
0
 
LVL 2

Author Comment

by:ChrisK
Comment Utility
OK, I just found the project under the vb5 samples that uses biblio.mdb with treeview...unfortunetly it doesn't help me out much.  I need an example that uses file listings, not information out of a database.  The whole goal here is to emulate the drive/dir/file list boxes so I can customize them with icons and other things.
0
 
LVL 1

Accepted Solution

by:
MAVERICK earned 70 total points
Comment Utility
I have an OCX which may help you!
You can get it from www.Comcache.com
 
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now