[RESOLVED] How Do I Fill ListBox With Infinite FileNames From a Folder?
I am working on another game show PC game at this moment. One based on the game show Press Your Luck, in fact.
However, I am now figuring out how to fill the list box with an infinite number of filenames in a folder. Any suggestions?
Re: How Do I Fill ListBox With Infinite FileNames From a Folder?
Quote:
Originally Posted by
JonSea31
an infinite number of filenames
You can't be serious!
What exactly are you trying to do ?
Re: How Do I Fill ListBox With Infinite FileNames From a Folder?
Did you, by chance, by infinite mean dynamic/changeable list of files?
In any case, you can look at the FileListBox control which will show a folders content by itself. If you want to load the list of files through code, I suggest you use a ListView instead (set to Report style, with one or more columns added). ListView is much faster, more flexible, and since it's index is Long integer based it can take over 2 billion items, whereas Listbox with it's Integer based index takes 32767 items, after which the counter gets messed up and indexes start going into negative numbers. Plus listbox is slow and basically just one column.
Re: How Do I Fill ListBox With Infinite FileNames From a Folder?
When I said "infinite", I don't mean thousands or millions of files. Right now, I have 45 text files in a folder, and I may add some more eventually. If I were to set a max of, say, 250 text files, what would I do?
EDIT: Just read badger's post - how would I do ListView?
Re: How Do I Fill ListBox With Infinite FileNames From a Folder?
For such a small amount of files the FileListBox will do fine. Just set the .Path property to the folder you want it to use and it will automatically load all the files in it. You can also set a mask to "*.txt" for example so it only shows text files. To enforce a limit you could check the ListCount property of the FileListBox, and if it the count is over a certain limit you can do what you want at that point.
For the ListView you would need to write your own code to load filenames to it, using Dir function, or FileSystemObject to go through all the files in a folder and adding them to the list. But if the count is below a couple of thousand you will be more than fine with FileListBox.
Re: How Do I Fill ListBox With Infinite FileNames From a Folder?
When I see this sort of thing I always wonder "Why not just have a button to bring up the Open and/or Save dialog from CommonControls?"
It really depends on what the point of showing such a file list is, but often it is simply to let users pick a file or files to open. For this sort of thing using a separate dialog saves Form real estate too.
Re: How Do I Fill ListBox With Infinite FileNames From a Folder?
I figured out the problem myself, with some help from badger. Thanks, folks - this thread is now resolved. :)