|
-
Mar 26th, 2010, 04:53 PM
#1
Thread Starter
Member
Re: List Box
Reply to #3
tech & wierd
This is my code now, I think I am missing a step? You mentioned "Once the items have been loaded"
I am not sure that I have loaded anything because my list box is still empty. So I can assume now that the original code posted above is just a browse function, the code you gave me is a list function, now I must figure out how to load the desired files. Makes sense. (but I don't know how to load items?) I will search the forum for how to load items and hopefully check back for maybe a reply on how to load items at a later time. hint, hint.
Thanks
Code:
Public Class Form1
Private Sub BtBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim BtBrowse As New FolderBrowserDialog()
BtBrowse.SelectedPath = "C:\"
If BtBrowse.ShowDialog() = Windows.Forms.DialogResult.OK Then
For Each File As String In My.Computer.FileSystem.GetFiles(BtBrowse.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
ListBox1.Items.Add(File)
Next
End If
End Sub
End Class
Last edited by VB_begginer; Mar 26th, 2010 at 04:58 PM.
-
Mar 26th, 2010, 05:04 PM
#2
Thread Starter
Member
Re: List Box
I got it to work... It helps if I am looking for the right file extention.
Thanks guys
-
Mar 27th, 2010, 08:37 AM
#3
Thread Starter
Member
Re: [RESOLVED] List Box
How do I get the listbox to only show the files? Example being only "file.txt" not c:\path......file.txt?
I am finding VB to be understandable once someone shows me the code, but I am finding it hard to be intuative.
Thanks
-
Mar 27th, 2010, 12:29 PM
#4
Hyperactive Member
Re: [RESOLVED] List Box
 Originally Posted by VB_begginer
How do I get the listbox to only show the files? Example being only "file.txt" not c:\path......file.txt?
I am finding VB to be understandable once someone shows me the code, but I am finding it hard to be intuative.
Thanks
As with so many things in VB.Net and programming in general there are many ways to do the same thing. If I were to do this then I would have done the following. Please note the Directory classes GetFiles() method returns file name with paths and the DirectoryInfo classes GetFiles() method returns file names without paths.
vb Code:
Dim dirInfo As New DirectoryInfo("C:\")
' Getting the files with .txt extension
Dim files() As FileInfo = dirInfo.GetFiles("*.txt")
' Adding the filenames to the listbox
For Each file As FileInfo In files
ListBox1.Items.Add(file.Name & Environment.NewLine())
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|