Results 1 to 19 of 19

Thread: [RESOLVED] List Box

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    33

    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.

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    33

    Re: List Box

    I got it to work... It helps if I am looking for the right file extention.

    Thanks guys

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    33

    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

  4. #4
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    Re: [RESOLVED] List Box

    Quote Originally Posted by VB_begginer View Post
    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:
    1. Dim dirInfo As New DirectoryInfo("C:\")
    2.  
    3. ' Getting the files with .txt extension
    4. Dim files() As FileInfo = dirInfo.GetFiles("*.txt")
    5.  
    6. ' Adding the filenames to the listbox
    7. For Each file As FileInfo In files
    8.    ListBox1.Items.Add(file.Name & Environment.NewLine())
    9. 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
  •  



Click Here to Expand Forum to Full Width