Results 1 to 6 of 6

Thread: Listbox with folder contents.

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Listbox with folder contents.

    So, I have a little GUI setup with a Listbox and a Richtextbox.

    I want the Listbox to display all of the .txt files displayed within a folder I have defined, then when a ListBox item is selexted, it displays the contents of that file within the RTB.

    I can't think of anything, mind is absolutely blank. Help?

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Listbox with folder contents.

    Well, coding is all about breaking things down into a managable set of instructions. First, you say you want to display a list of all .txt files. So, a quick search on how to get a list of files points at here, with an example similar to your needs. Next up is knowing when a listbox item is selected, which is given to us by an event here. Last of all, you need to get the contents of a file into a RTB, which actually has its own method to do this here.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Listbox with folder contents.

    I was unaware of those methods, thank you. Will give them a whirl.

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Listbox with folder contents.

    Ok, so when trying to load the file into the ListBox I need to add quotation marks to the beginning and end of the string:

    vb Code:
    1. Dim path As String = """ & ListBox1.Text & """
    2.  
    3.         info.LoadFile(path, RichTextBoxStreamType.PlainText)

    But obviously the
    vb Code:
    1. """ & info.Text & """

    Selects "" & ListBox1.text & "" as the path because of the quotation marks.


    How would I get around this? :S
    Last edited by ComYOU; Feb 16th, 2012 at 07:13 PM.

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Listbox with folder contents.

    Text is a string member. So info.Text is a string.

    Code:
    Dim path As String = info.Text

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Listbox with folder contents.

    Nevermind, using the
    vb Code:
    1. Chr(34)
    code.

    EDIT:

    I'm using the
    vb Code:
    1. For Each foundFile As String
    2.                 In My.Computer.FileSystem.GetFiles(direct, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
    3.  
    4.  
    5.                 List.Items.Add(foundFile)
    6.             Next
    to add the file directory to the ListBox, but how would I only add the name?

    EG - Instead of adding C:\Users\ComYOU\Documents\help.txt" it would only add the "help", or possibly "help.txt"?


    EDIT: Sorted, no need for the thread anymore.
    Last edited by ComYOU; Feb 16th, 2012 at 08:36 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width