open a seleced folder and have its files put into a list box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jebtrillion
    New Member
    • May 2007
    • 12

    open a seleced folder and have its files put into a list box

    Hello everyone,

    I need some help with the folder browser dialog. I need to be able to open a seleced folder and have its files put into a list box.

    If anyone can help that would be great.

    Thanks for taking the time to read this.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by jebtrillion
    I need some help with the folder browser dialog. I need to be able to open a seleced folder and have its files put into a list box.
    I'm going to assume, since you didn't say, that you're using VB6.

    Probably the simplest thing would be to use a FileListBox control, and just set its .Path property to match the selected directory. (I think you can only set this property in code at runtime, not in design mode.)

    Comment

    • jebtrillion
      New Member
      • May 2007
      • 12

      #3
      Thanks

      Ill see if it works but I would much rather have it do it through my way just because it is going to be a program for everyone and not just myself.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by jebtrillion
        Thanks

        Ill see if it works but I would much rather have it do it through my way just because it is going to be a program for everyone and not just myself.
        You can certainly use a regular listbox if you prefer. I was just suggesting a FileListBox is simpler. After all, that's what it is designed for. And it is one of the standard controls supplied with VB, so there's nothing extra to add. (Unless you have the edition that doesn't have most of the controls, I suppose.)

        To load up an ordinary listbox you could just do something like this...

        [CODE=vb]' Assumptions:
        ' 1 - Dir1 is a DirListBox in which you have selected a directory.
        ' 2 -List1 is your listbox.
        Dim FileName As String
        FileName = Dir$(Dir1.Path & "\*.*")
        List1.Clear
        Do While FileName <> ""
        List1.AddItem FileName
        FileName = Dir ' No parameters means to return next match.
        Loop[/CODE]

        Comment

        • jebtrillion
          New Member
          • May 2007
          • 12

          #5
          I tryed it and when I use your sample code this is the message I get concerning the listbox:

          'Clear' is not a member of 'System.Windows .Forms.ListBox' .

          I also get this error message:


          'AddItem' is not a member of 'System.Windows .Forms.ListBox' .

          Comment

          • jebtrillion
            New Member
            • May 2007
            • 12

            #6
            Ok i got it to work thanks

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by jebtrillion
              Ok i got it to work thanks
              Had to adjust for version differences, huh? :)

              Glad to hear you got it going, anyway.

              Comment

              • coolminded
                New Member
                • Mar 2007
                • 137

                #8
                Originally posted by Killer42
                You can certainly use a regular listbox if you prefer. I was just suggesting a FileListBox is simpler. After all, that's what it is designed for. And it is one of the standard controls supplied with VB, so there's nothing extra to add. (Unless you have the edition that doesn't have most of the controls, I suppose.)

                To load up an ordinary listbox you could just do something like this...

                [CODE=vb]' Assumptions:
                ' 1 - Dir1 is a DirListBox in which you have selected a directory.
                ' 2 -List1 is your listbox.
                Dim FileName As String
                FileName = Dir$(Dir1.Path & "\*.*")
                List1.Clear
                Do While FileName <> ""
                List1.AddItem FileName
                FileName = Dir ' No parameters means to return next match.
                Loop[/CODE]
                This code works properly,
                but what i want to ask is can we change the drive name also.
                i.e. it shows only the content of the "c:\" drive. if i want to see the content of "d:\" drive or any other drive, what should be done?

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by coolminded
                  This code works properly,
                  but what i want to ask is can we change the drive name also.
                  i.e. it shows only the content of the "c:\" drive. if i want to see the content of "d:\" drive or any other drive, what should be done?
                  Sure. If you have a look at what's in the .Path property, you'll find it includes the drive. You can just change it there.

                  Usually the DriveListBox and DirListBox controls are used in conjunction to provide this sort of functionality. When the user changes the DriveListBox, you update the path on the DirListBox to match.

                  Comment

                  Working...