none
Displaying list of text in a TextBox

    Question

  • I'm a novice programmer and I have a very basic question.  I am trying to display text in a TextBox, with one caveat.  I need to be able to insert "carriage returns" or force the text onto a new line.  I am using the text box to display the results of a numbered list.  How can this be done?

    As a work around I am using Word to display the results, but ideally the application needs to be able to display the results in a text box.

    Thank you for any help you can provide.

    Monday, March 06, 2006 3:18 PM

Answers

  • vbCrLf works fine for me, what is the difference between the two ?

     

    str = item1 & vbcrlf & item2 & vbcrlf

    Monday, March 06, 2006 8:26 PM

All replies

  • You can set the multiline attribute to true.
    Monday, March 06, 2006 3:27 PM
  • I've done that, but I need to some how force a new line after each list item.  Curruently I have a numbered list strung together.  I need each numbered item to appear on it's own line.  Each lsit item maybe 1 or more lines in length.  Any thoughts?
    Monday, March 06, 2006 3:54 PM
  • How do you convert your numbered list into a string ? You could of vbCrLf.
    Monday, March 06, 2006 4:00 PM
  • This trick has worked for me regarding Tooltips and I think that it can work with text boxes as well. You can use the "environment.NewLine" command to start a new line. You must string it together just as if it was a normal string.

    Example:

    Textbox.text = "This example will start a new line" & environment.NewLine & "NOW"

    Monday, March 06, 2006 4:06 PM
  • I tried adding evironment.NewLine and I'm getting an error: 424 Run-time Error.  Object required.

    I'm not much of a programmer.  Do I need to substitute an object for the word "environment" in the line of code you suggested?

    Monday, March 06, 2006 6:19 PM
  • Check this out:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemenvironmentclassnewlinetopic.asp

    It seems like you should be able to use this, but I've never tried it in a text box. Did you set the textbox to allow multiline text?

    Monday, March 06, 2006 6:47 PM
  • vbCrLf works fine for me, what is the difference between the two ?

     

    str = item1 & vbcrlf & item2 & vbcrlf

    Monday, March 06, 2006 8:26 PM
  • Brilliant!  That did it.  The vbCrLf was the command I was looking for.  Thank you so much.  This has been frustrating me for over a week.
    Monday, March 06, 2006 9:20 PM
  •  

    vbCrLf and Environment.NewLine produce the same result; specifically, a carriage return and line feed characters. Should the .NET framework be implemented on, say, a unix platform, then they may (would) be different. Lookup the .NewLine property in Help.

    Note that if you are having issues with Environment.NewLine, then you may have other problems, too: by default, Environment.Newline should be available to you for use.

    Monday, March 06, 2006 9:28 PM
  • ''If it were me I would make the textbox multi line then do something like this:

    Private Const LINE_ITEM_FORMAT as String = "{0}) {1}" & vbCrLf

    Private itemList As String

    itemList += String.Format(LINE_ITEM_FORMAT, 1, "the first item")
    itemList += String.Format(LINE_ITEM_FORMAT, 2, "the second item")
    itemList += String.Format(LINE_ITEM_FORMAT, 3, "the third item")
    itemList += String.Format(LINE_ITEM_FORMAT, 4, "the forth item")

    TextBox1.Text = itemList

    ''If you list is broken up by commas or some other delimiter you can use String.Split to create an array of items you can loop though.
    Tuesday, March 07, 2006 8:25 PM