How do I list all the files in a folder and select one.
-
In VB.Net is there a simple way of displaying all the files in a selected folder depending on a criteria and how would you display via a message box the file selected. Is it something like as follows. Getting mixed up with VB 6 and .net. I have a dirlistbox, drivelistbox and a filelistbox. I can get a connection between drive and folder but what is the syntax for the files. Feeling stupid here. Private Sub drvLoc_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drvLoc.SelectedIndexChanged dirLoc.Path = drvLoc.Drive End Sub
-
In VB.Net is there a simple way of displaying all the files in a selected folder depending on a criteria and how would you display via a message box the file selected. Is it something like as follows. Getting mixed up with VB 6 and .net. I have a dirlistbox, drivelistbox and a filelistbox. I can get a connection between drive and folder but what is the syntax for the files. Feeling stupid here. Private Sub drvLoc_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drvLoc.SelectedIndexChanged dirLoc.Path = drvLoc.Drive End Sub
You would want to use a
ComboBox
and aListBox
for this. Like so:Private Sub DriveComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveComboBox.SelectedIndexChanged
FolderListBox.Items.Clear()
For Each Dir As String In My.Computer.FileSystem.GetDirectories(DriveComboBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
FolderListBox.Items.Add(Dir)
Next
End SubPrivate Sub FolderListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FolderListBox.SelectedIndexChanged
FileListBox.Items.Clear()
For Each File As String In My.Computer.FileSystem.GetFiles(FolderListBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
FileListBox.Items.Add(File)
Next
End SubPrivate Sub FileListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox.SelectedIndexChanged
MsgBox(FileListBox.SelectedItem)
End SubThe
DriveListBox, DirListBox
and theFileListBox
are not what you would want to use for this. Microsoft doesn't even offer support for these controls anymore. Plus,ListBoxes
are a lot more customizable. Hope this helps.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
You would want to use a
ComboBox
and aListBox
for this. Like so:Private Sub DriveComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveComboBox.SelectedIndexChanged
FolderListBox.Items.Clear()
For Each Dir As String In My.Computer.FileSystem.GetDirectories(DriveComboBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
FolderListBox.Items.Add(Dir)
Next
End SubPrivate Sub FolderListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FolderListBox.SelectedIndexChanged
FileListBox.Items.Clear()
For Each File As String In My.Computer.FileSystem.GetFiles(FolderListBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
FileListBox.Items.Add(File)
Next
End SubPrivate Sub FileListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox.SelectedIndexChanged
MsgBox(FileListBox.SelectedItem)
End SubThe
DriveListBox, DirListBox
and theFileListBox
are not what you would want to use for this. Microsoft doesn't even offer support for these controls anymore. Plus,ListBoxes
are a lot more customizable. Hope this helps.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
You would want to use a
ComboBox
and aListBox
for this. Like so:Private Sub DriveComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveComboBox.SelectedIndexChanged
FolderListBox.Items.Clear()
For Each Dir As String In My.Computer.FileSystem.GetDirectories(DriveComboBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
FolderListBox.Items.Add(Dir)
Next
End SubPrivate Sub FolderListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FolderListBox.SelectedIndexChanged
FileListBox.Items.Clear()
For Each File As String In My.Computer.FileSystem.GetFiles(FolderListBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
FileListBox.Items.Add(File)
Next
End SubPrivate Sub FileListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox.SelectedIndexChanged
MsgBox(FileListBox.SelectedItem)
End SubThe
DriveListBox, DirListBox
and theFileListBox
are not what you would want to use for this. Microsoft doesn't even offer support for these controls anymore. Plus,ListBoxes
are a lot more customizable. Hope this helps.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
Forgot to mebtion I am using visual studio 2003 and the name my and FileIO does not work. How is this done in 2003. Sorry for this
Well, I can't really help much with anything in VS2003, but you could go ahead and use a Drive, Directory and File ListBox (since you are using an older version of VS). So, try this:
Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChanged
DirListBox1.Path = DriveListBox1.Drive
End Sub
Private Sub FolderListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DirListBox1.SelectedIndexChanged
FileListBox1.Path = DirListBox1.Path
End Sub
Private Sub FileListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox1.SelectedIndexChanged
MsgBox(FileListBox1.SelectedItem)
End Sub
Hope this helps!
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.