Populate combobox from contents of folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gobblegob
    New Member
    • Dec 2007
    • 133

    Populate combobox from contents of folder

    hi guys,

    I would like to populate a combobox list with the contents of a folder which contains text files , which will later be opened.

    Thanks in advanced for any help :)

    Gobble.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Kindly post what you have tried.

    NOTE: Try to use Filelistbox for the purpose.

    Comment

    • gobblegob
      New Member
      • Dec 2007
      • 133

      #3
      Originally posted by debasisdas
      Kindly post what you have tried.

      NOTE: Try to use Filelistbox for the purpose.

      Well i couldnt work how to add all folder contents to a combobox, But i did workout another way to do what i need.


      Code:
          Dim combolist As String
          Combo1.Clear
          Open "c:\list\listpop.txt" For Input As #1
          Do While EOF(1) = False
          Line Input #1, combolist
          Combo1.AddItem combolist
          Loop
        Close #1

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Does the text file contains the list of files in the folder.

        Comment

        • jamesd0142
          Contributor
          • Sep 2007
          • 471

          #5
          This is vb.net code:

          [code=vbnet]
          Private Sub load()
          ComboBox1.Items .Clear()
          ComboBox1.Text = Nothing
          'Dim startpath As String = "C:\a"
          Dim myfolder As DirectoryInfo = New DirectoryInfo(s tartpath & "\")

          'get all file in folder with .txt extension
          Dim strFiles() As FileInfo = myfolder.GetFil es("*.txt")

          'for each file add to combobox
          For Each myItem As FileInfo In strFiles
          ComboBox1.Items .Add(myItem)
          Next
          End Sub
          [/code]

          Comment

          Working...