?
Solved

Showind directories in listview boxes

Posted on 2003-03-26
5
Medium Priority
?
149 Views
Last Modified: 2010-05-01
Hi,

I want the list box to be able to view directories only.

i have the following path:

C:\Reports\S004\index.html
C:\Reports\S004\tick.jpg
C:\Reports\S004\cross.jpg
C:\Reports\S005\index.html
C:\Reports\S005\tick.jpg
C:\Reports\S015\cross.jpg
C:\Reports\S015\index.html
C:\Reports\S015\tick.jpg
C:\Reports\S015\cross.jpg

I want to only see in my list box

S004, S005 and S015 as icons.

But i don't want to add it manualy as items get added all the time.

Thanks,
Bernard
0
Comment
Question by:sexy-sx
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:robertlees
ID: 8216085
To populate ListBox with all the directories on your C drive...

Call ShowDirectories("c:\")

Sub ShowDirectories(ByVal strDirectory As String)
    Dim aryDirectories() As String
    Dim d As Integer
    Dim n As Integer
    Dim strFile As String
   
    d = 1
    ReDim aryDirectories(d)
    aryDirectories(d) = strDirectory
   
    Do
        If d > UBound(aryDirectories) Then Exit Do
        strDirectory = aryDirectories(d)
        d = d + 1
        If Right(strDirectory, 1) <> "\" Then
            strDirectory = strDirectory & "\"
        End If
       
        strFile = Dir(strDirectory & "*.*", 31)
        Do Until strFile = ""
            If Left(strFile, 1) <> "." Then
                If GetAttr(strDirectory & strFile) = vbDirectory Then
                    n = UBound(aryDirectories) + 1
                    ReDim Preserve aryDirectories(n)
                    aryDirectories(n) = strDirectory & strFile
                End If
            End If
            strFile = Dir
        Loop
    Loop
   
    For d = 1 To UBound(aryDirectories)
        ListBox.AddItem aryDirectories(d)
    Next d
End Sub
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8217503
If you want to see the directories as icons I think you will have to use the Listview Control instead of a Listbox.
0
 

Author Comment

by:sexy-sx
ID: 8220900
sorry, i was meant to say listview box
0
 
LVL 1

Accepted Solution

by:
robertlees earned 200 total points
ID: 8221380
To populate a ListView rather than a listbox, place a ListView and an ImageList on your form. Add a Folder icon to the ImageList, and give it a key of "Folder". Link the ImageList to the ListView. Ensure the View property of the ListView is '0 - Icon'. I've amended the code slightly.


Sub ShowDirectories(ByVal strDirectory As String)
   Dim aryDirectories() As String
   Dim d As Integer
   Dim n As Integer
   Dim strFile As String
   
   d = 1
   ReDim aryDirectories(d)
   aryDirectories(d) = strDirectory
   
   Do
       If d > UBound(aryDirectories) Then Exit Do
       strDirectory = aryDirectories(d)
       d = d + 1
       If Right(strDirectory, 1) <> "\" Then
           strDirectory = strDirectory & "\"
       End If
       
       strFile = Dir(strDirectory & "*.*", 31)
       Do Until strFile = ""
           If Left(strFile, 1) <> "." And LCase(Right(strFile, 4)) <> ".sys" Then
               If GetAttr(strDirectory & strFile) = vbDirectory Then
                   n = UBound(aryDirectories) + 1
                   ReDim Preserve aryDirectories(n)
                   aryDirectories(n) = strDirectory & strFile
               End If
           End If
           strFile = Dir
       Loop
   Loop
   
   For d = 1 To UBound(aryDirectories)
       ListView1.ListItems.Add , , aryDirectories(d), "Folder"
   Next d
End Sub
0
 

Author Comment

by:sexy-sx
ID: 8221692
Thanks,

That work great!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

578 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