Results 1 to 9 of 9

Thread: ListView question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849
    I need to use the ListView to nevigate through the
    windows files.
    Can I do that and how?
    Dekel C.

  2. #2
    Guest
    Here you go.

    You first need a listview, an imagelist with 2 images, the 1st for folder and the 2nd one for file, and an "GO UP" command button. Use default names.

    Code:
    Option Explicit
    
    Private fso As New FileSystemObject
    Private fl As File
    Private fls As Files
    Private fld As Folder
    Private fldl As Folder
    
    Private currfldr As String
    
    Private Sub Command1_Click()
        Dim itmp As Byte, xc As Boolean
        Set fld = fld.ParentFolder
        Set fls = fld.Files
        ListView1.ListItems.Clear
        For Each fldl In fld.SubFolders
            ListView1.ListItems.Add , , fldl.Name, 1, 1
            itmp = fldl.Attributes
            If itmp >= 128 Then itmp = itmp - 128
            If itmp >= 64 Then itmp = itmp - 64
            If itmp >= 32 Then itmp = itmp - 32
            If itmp >= 16 Then itmp = itmp - 16
            If itmp >= 8 Then itmp = itmp - 8
            If itmp >= 4 Then itmp = itmp - 4
            If itmp = 2 Or 3 Then ListView1.ListItems(ListView1.ListItems.Count).Ghosted = True
        Next
        For Each fl In fls
            ListView1.ListItems.Add , , fl.Name, 2, 2
            itmp = fl.Attributes
            If itmp >= 128 Then itmp = itmp - 128
            If itmp >= 64 Then itmp = itmp - 64
            If itmp >= 32 Then itmp = itmp - 32
            If itmp >= 16 Then itmp = itmp - 16
            If itmp >= 8 Then itmp = itmp - 8
            If itmp >= 4 Then itmp = itmp - 4
            If itmp = 2 Or 3 Then ListView1.ListItems(ListView1.ListItems.Count).Ghosted = True
        Next
        Exit Sub
        
    End Sub
    
    Private Sub Form_Load()
        Dim itmp As Byte
        ListView1.Sorted = True
        ListView1.Checkboxes = True
        currfldr = "C:\"
        Set fld = fso.GetFolder(currfldr)
        Set fls = fld.Files
        For Each fldl In fld.SubFolders
            ListView1.ListItems.Add , , fldl.Name, 1, 1
            itmp = fldl.Attributes
            If itmp >= 128 Then itmp = itmp - 128
            If itmp >= 64 Then itmp = itmp - 64
            If itmp >= 32 Then itmp = itmp - 32
            If itmp >= 16 Then itmp = itmp - 16
            If itmp >= 8 Then itmp = itmp - 8
            If itmp >= 4 Then itmp = itmp - 4
            If itmp = 2 Or 3 Then ListView1.ListItems(ListView1.ListItems.Count).Ghosted = True
        Next
        For Each fl In fls
            ListView1.ListItems.Add , , fl.Name, 2, 2
            itmp = fl.Attributes
            If itmp >= 128 Then itmp = itmp - 128
            If itmp >= 64 Then itmp = itmp - 64
            If itmp >= 32 Then itmp = itmp - 32
            If itmp >= 16 Then itmp = itmp - 16
            If itmp >= 8 Then itmp = itmp - 8
            If itmp >= 4 Then itmp = itmp - 4
            If itmp = 2 Or 3 Then ListView1.ListItems(ListView1.ListItems.Count).Ghosted = True
        Next
    End Sub
    
    Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
        Dim itmp As Byte
        If Item.Icon = 2 Then GoTo extfile
        currfldr = currfldr & Item.Text & "\"
        Set fld = fso.GetFolder(currfldr)
        Set fls = fld.Files
        ListView1.ListItems.Clear
        For Each fldl In fld.SubFolders
            ListView1.ListItems.Add , , fldl.Name, 1, 1
            itmp = fldl.Attributes
            If itmp >= 128 Then itmp = itmp - 128
            If itmp >= 64 Then itmp = itmp - 64
            If itmp >= 32 Then itmp = itmp - 32
            If itmp >= 16 Then itmp = itmp - 16
            If itmp >= 8 Then itmp = itmp - 8
            If itmp >= 4 Then itmp = itmp - 4
            If itmp = 2 Or 3 Then ListView1.ListItems(ListView1.ListItems.Count).Ghosted = True
        Next
        For Each fl In fls
            ListView1.ListItems.Add , , fl.Name, 2, 2
            itmp = fl.Attributes
            If itmp >= 128 Then itmp = itmp - 128
            If itmp >= 64 Then itmp = itmp - 64
            If itmp >= 32 Then itmp = itmp - 32
            If itmp >= 16 Then itmp = itmp - 16
            If itmp >= 8 Then itmp = itmp - 8
            If itmp >= 4 Then itmp = itmp - 4
            If itmp = 2 Or 3 Then ListView1.ListItems(ListView1.ListItems.Count).Ghosted = True
        Next
        Exit Sub
        
    extfile:
        Shell currfldr & Item.Text, vbNormalFocus
    End Sub

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849
    Thanks
    but when I try to run it, ut tells me that
    Private fso As New FileSystemObject
    is not user-defined or something.
    Dekel C.

  4. #4
    Guest

    Lightbulb Sorry, I forgot to tell you...

    Add "Microsoft Scripting Runtime" in your project references. That should solve the error.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849
    Thanks, but another problem came up:
    it tells me that I need ti initialize my ImageList.
    Dekel C.

  6. #6
    Guest
    Yes, sorry.

    You also have to right click the listview, choose "Properties" on the popup menu, click on "Image Lists", and set all three combos into the imagelist that you've just created.

    That should solve everything, but let me know if there is another.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849
    It's great!
    But still not perfect.
    first of all, why are all the file are CheckBoxes?
    and second, on some folders the click does not work?
    Dekel C.

  8. #8
    Guest
    Well, actually, clicking on a checkbox would open the file/folder, and you click the CHECKBOX, not the icon, to open it. You may need to select a file and there isn't a DOUBLE-CLICK event for individual items.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849
    Well, thanks anyway.
    does anyone knows how to solve this?
    Dekel C.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width