?
Solved

Showind directories in listview boxes

Posted on 2003-03-26
5
Medium Priority
?
147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

752 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