List box used to open files, advice/help?
Hey, I'm working on a project, basically writing a small application intended to allow the user to open files from a specific directory, edit them without saving (through a RTE), then export the edited content to a word document using bookmarks.
Part of this program I would truly like to add would be a list box displaying the name of files in a specific directory - and for the user to be able to click on each file name in the list box, and for the file contents to display within my RTE. Is this possible? Any advice, help or tutorials would be greatly appreciated.
Re: List box used to open files, advice/help?
Quote:
I would truly like to add would be a list box displaying the name of files in a specific directory
Check this one: http://www.vbforums.com/showpost.php...79&postcount=3 ...:wave:
Re: List box used to open files, advice/help?
Thanks for that :D That solves part 1 of my problem, part 2, making them act as links to open the files... that's the real stumper.
Re: List box used to open files, advice/help?
What kind of files are they?
Re: List box used to open files, advice/help?
Try something like this:
Code:
RichTextBox1.LoadFile "c:\" & List1.ListIndex
LoadFile will load the file to the Richtextbox (parameter passed is the file location).
If you have populated the listbox from C drive, and List1 contains filenames, then the above code will work.
List1.ListIndex will give the filename of the selected item in Listbox.
I think this will help you... If you have any doubts, please post it... :wave:
Re: List box used to open files, advice/help?
And what happens if the file is not a text file?
Re: List box used to open files, advice/help?
Quote:
Originally Posted by
Hack
And what happens if the file is not a text file?
Good point. The list of file names will have to be parsed to determine what kind of file it is before any attempt is made by the program to open it and do something with it.
Re: List box used to open files, advice/help?
The link posted in post #2, contains an example Sub for loading files from a folder... It has an optional parameter for the extension of the file. So, the files that are loaded into listbox can be controlled by using the extension. ie. here we will be passing the parameter rtf for the extension. That will make sure that, only the RichTextFormatted files are populated in the listbox.
So, for loading the file in a RichTextBox control(ie. the selected file in ListBox control), use the sample code in post #5 ...:wave:
Re: List box used to open files, advice/help?
Sorry for the delayed reply, internet troubles.
The files I'll primarily be loading will be html format.
I'll attempt your suggestions and see how it goes, thank you for your advice and expertise, I very much appreciate it and hope it works :)
Re: List box used to open files, advice/help?
Quote:
Originally Posted by
taliesan
Sorry for the delayed reply, internet troubles.
The files I'll primarily be loading will be html format.
I'll attempt your suggestions and see how it goes, thank you for your advice and expertise, I very much appreciate it and hope it works :)
Be aware that you cannot trust the file extension to determine what the file format really is. You have to examine the file itself to determine whether and how it should be opened and with what. You can always open a file in Binary mode, but after that, you have to determine what to do with it.
Re: List box used to open files, advice/help?
Hmn so i've been trying out the suggested solutions today and ran into a problem. I'm using visual studio 5 (as a more familiar environment) and after attempting to display my folders contained files within my list box got the error:
'AddItem' is not a member of 'System.Windows.Forms.ListBox
Re: List box used to open files, advice/help?
That error shows you are not using VB 5 (aka VB 1997), but some form of VB.Net (presumably VB 2005)
Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum