7 Replies - 4863 Views - Last Post: 02 July 2011 - 10:16 PM Rate Topic: -----

#1 leadfirelf  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 189
  • Joined: 11-February 11

Choosing file to show in textbox

Posted 27 June 2011 - 01:43 PM

Hey,
I have a listbox with file names in them, I want to be able to view the contents of those files by using a textbox on the side, advice?

Code I tried below:

        Dim data As String
        data = My.Computer.FileSystem.ReadAllText(ListBox1.SelectedItem)
        TextBox1.Text = data


Is This A Good Question/Topic? 0
  • +

Replies To: Choosing file to show in textbox

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9088
  • View blog
  • Posts: 34,139
  • Joined: 12-June 08

Re: Choosing file to show in textbox

Posted 27 June 2011 - 01:48 PM

That's questionable. What sort of files are they? Exectuables? Images? a .TXT? .ISO? Depending on the file it alters what sort of "contents" you are talking about.

What's wrong with your code? Is there an error? If so where and what? Is it not performing as expected? If so what is it doing? what should it be doing?

You can also use StreamReader as well.
Was This Post Helpful? 0
  • +
  • -

#3 Btu  Icon User is offline

  • D.I.C Regular

Reputation: 36
  • View blog
  • Posts: 250
  • Joined: 16-May 11

Re: Choosing file to show in textbox

Posted 27 June 2011 - 02:49 PM

you'll need to implement streamreader to read the text files and spit the data into the text box. (assuming these files contain text)

This post has been edited by Btu: 27 June 2011 - 02:50 PM

Was This Post Helpful? 0
  • +
  • -

#4 leadfirelf  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 189
  • Joined: 11-February 11

Re: Choosing file to show in textbox

Posted 28 June 2011 - 01:28 PM

just simple text files displayed in a listbox, my problem is is that I know that on program launch it displays the text files but when they are clicked there is no action and the program just sits
--
Also unfortunately my computer failed and this post is being made off of a library computer :P. I'll try the streamreader but until I fix it here's a picture of a cat

Posted Image
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9088
  • View blog
  • Posts: 34,139
  • Joined: 12-June 08

Re: Choosing file to show in textbox

Posted 28 June 2011 - 01:33 PM

Ah.. okay. I am not sure how to respond to that out side of, show us your code?
Was This Post Helpful? 0
  • +
  • -

#6 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Choosing file to show in textbox

Posted 01 July 2011 - 05:40 AM

hi leadfirelf,
From what you put it sounds like you got the listbox to correctly display the files. You mention when when you click on the file name in the listbox that nothing happens. Did you program it to do anything when you click in the listbox such as when this item is clicked, read that file into the textbox? As mentioned you should use streamreader, use the selecteditem to see whats selected in the listbox and then use that to tell the streamreader what file to read into the textbox. Hope that helps some. Also as Modi mentioned, if we could see your code that would be helpful.

Sam
Was This Post Helpful? 0
  • +
  • -

#7 leadfirelf  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 189
  • Joined: 11-February 11

Re: Choosing file to show in textbox

Posted 02 July 2011 - 09:42 PM

I still do not have my source code due to computer failure, I'm on my phone posting this one, I have my listbox giving the file directory as ".\folder\file.txt" when the item is clicked I want it to immediatly display the contents inside a textbox.


P.S. I'll post source in about a day, I am a little to lazy to fix the computer now.
Was This Post Helpful? 0
  • +
  • -

#8 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Choosing file to show in textbox

Posted 02 July 2011 - 10:16 PM

Since the list box has the address of your file, then you just get the selectedItem.ToString() and add it in StreamReader() which Btu showed you, Then after loading the data from file just add them to the textBox. What is your problem exactly? You get error or dont know how to?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1