I need to use the ListView to nevigate through the
windows files.
Can I do that and how?
Printable View
I need to use the ListView to nevigate through the
windows files.
Can I do that and how?
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
Thanks
but when I try to run it, ut tells me that
Private fso As New FileSystemObject
is not user-defined or something.
Add "Microsoft Scripting Runtime" in your project references. That should solve the error:).
Thanks, but another problem came up:
it tells me that I need ti initialize my ImageList.
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.
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?
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:).
Well, thanks anyway.
does anyone knows how to solve this?