Results 1 to 4 of 4

Thread: [2008] listbox help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    100

    [2008] listbox help

    Hey,

    I'm having some trouble with list boxes at the moment. I need a list box to display the names of directories that are in certain a folder. How can I do this? Thanks in advance!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2008] listbox help

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.    For Each folder As String In IO.Directory.GetDirectories("c:\red_bull_NRG")
    3.        ListBox1.Items.Add(IO.Path.GetFileName(folder))
    4.    Next
    5. End Sub

  3. #3
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2008] listbox help

    First issue is related to directories so first search in forums how you can find directories in particular folder.

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2008] listbox help

    You can use the IO.Directory.GetDirectories() method for that, like this:

    vb Code:
    1. For Each Directory As String In IO.Directory.GetDirectories("C:\", "*", IO.SearchOption.TopDirectoryOnly)
    2.      MyListBox.Items.Add(Directory)
    3. Next
    As you can see from the arguments I have passed in, I am just setting it to search the root of the C drive for folders and I have told it to not search subdirectories too.
    There is an equivalent method for files (unsurprisingly called GetFiles) too. I think both are available in My.Computer.FileSystem as well as the IO namespace

    EDIT: Damn Hack beat me to it
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


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