vb.net - How do i load a text file from a listbox if the name is unkown in visual basic -


so sitting here trying work open have 2 listboxs 1st selection list , if click on 1 of options pulls list of files , places them in listbox2.

now trying workout how open files pulled in listbox if 1 selected in richtextbox.

this have far, listbox 2is not working:

private sub listbox1_selectedindexchanged(sender object, e eventargs) handles listbox1.selectedindexchanged     if listbox1.text = "custom"         dim folderinfo new io.directoryinfo("c:\users\a\desktop\project1\project1\my project\responses\custom")         dim arrfilesinfolder() io.fileinfo         dim fileinfolder io.fileinfo         arrfilesinfolder = folderinfo.getfiles("*.*")         each fileinfolder in arrfilesinfolder             listbox2.items.add(fileinfolder.name)         next      end if end sub  private sub listbox2_selectedindexchanged(sender object, e eventargs) handles listbox2.selectedindexchanged     dim myfile string = dir$("c:\users\a\desktop\project1\project1\my project\responses\custom\*.*")      'check if file exists     if system.io.file.exists(myfile) = true         'read file         dim objreader new system.io.streamreader(myfile)          'save file contents textbox         richtextbox1.text = objreader.readtoend         objreader.close()     else         msgbox("file not found!")     end if end sub 

end class

thanks in advance.

your listbox2 sub should this:

private sub listbox2_selectedindexchanged(sender object, e eventargs) handles listbox2.selectedindexchanged     dim myfile string = "c:\users\a\desktop\project1\project1\my project\responses\custom\" & listbox2.selecteditem      'check if file exists     if system.io.file.exists(myfile) = true         'read file         dim objreader new system.io.streamreader(myfile)          'save file contents textbox         richtextbox1.text = objreader.readtoend         objreader.close()     else         msgbox("file not found!")     end if end sub 

more specifically, myfile should made of path , listbox selected item, i.e. file name.

so:

enter image description here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -