Results 1 to 3 of 3

Thread: Combobox to populate with Folder list

  1. #1
    zendog1960's Avatar
    zendog1960 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jan 2008
    Posts
    19
    Reputation
    55

    Question Combobox to populate with Folder list

    Morning all!

    I have a winform that has one combobox. I want to populate that it with a list of folders in a directory. I thought this might be a common thing but I have not found any thing concerning this.

    For this example lets say the root folder is C:\Testing\Folder List\

    In the folder "Folder List" directory there are 5 folders as such:

    Folder 1
    Folder 2
    Folder 3
    Folder 4
    Folder 5

    I would like the combobox to reflect the names of the folders, i.e Folder 1 thru Folder 5. This must be somewhat dynamic in that users may create and delete folders in the "Folder List" folder daily so at runtime this needs to go get the current list from the location.

    I for the life of me cannot find anything to help me with this. Keep in mind I am learning all this as I go so be gentle!

    Thank you all for your quick responses and help!

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    13,315
    Reputation
    1991
    Code:
    Me.FoldersComboBox.DataSource = (From folder In New IO.DirectoryInfo("C:\Testing\Folder List\").GetDirectories Select (folder.Name)).ToArray
    You can find file and folder tools in System.IO namespace.

  3. #3
    zendog1960's Avatar
    zendog1960 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jan 2008
    Posts
    19
    Reputation
    55
    Thanks John.

    I actually can up with this code and it works. Seems to be longer than your however.

    Code:
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            ' Make a reference to a directory.
            Dim di As New DirectoryInfo("C:\Testing\Folder List\")
            ' Get a reference to each directory in that directory.
            Dim diArr As DirectoryInfo() = di.GetDirectories()
            ' Populate Combobox.
            Dim dri As DirectoryInfo
            For Each dri In diArr
                cboxClient.Items.Add(dri.Name)
            Next dri
    End Sub

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO