Writing to a Multiline Textbox programmatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anil Gupte

    Writing to a Multiline Textbox programmatically


    I have read a lot about getting lines from a multiline textbox in VB.Net.
    However, I cannot for the life of me figure out how to write to a multiline
    textbox. Basically, I have created an array of strings which I want to
    "paste" into a multiline textbox. Any ideas?


    --
    Anil Gupte




  • rowe_newsgroups

    #2
    Re: Writing to a Multiline Textbox programmaticall y

    On Sep 7, 7:36 am, "Anil Gupte" <anil-l...@icinema.co mwrote:
    I have read a lot about getting lines from a multiline textbox in VB.Net.
    However, I cannot for the life of me figure out how to write to a multiline
    textbox. Basically, I have created an array of strings which I want to
    "paste" into a multiline textbox. Any ideas?
    >
    --
    Anil Guptewww.keenin c.netwww.icinem a.com
    You mean something like this:

    //////////////
    Dim strings As String() = {"one", "two", "three", "four"}

    For Each s As String In strings
    Me.TextBox1.Tex t += s
    Me.TextBox1.Tex t += Environment.New Line
    Next
    //////////////

    Thanks,

    Seth Rowe

    Comment

    • Anil Gupte

      #3
      Re: Writing to a Multiline Textbox programmaticall y

      That does seem to work. Here is what I tried:

      Dim strLine As String
      Dim n As Integer = 0
      For Each strLine In AllLines
      txtBoxSliceInfo All(n) = strLine
      n = n + 1
      Next strLine

      Just curious as to why that did not work

      Thanx,
      --
      Anil Gupte



      "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
      news:1189167481 .805733.205040@ 19g2000hsx.goog legroups.com...
      On Sep 7, 7:36 am, "Anil Gupte" <anil-l...@icinema.co mwrote:
      >I have read a lot about getting lines from a multiline textbox in VB.Net.
      >However, I cannot for the life of me figure out how to write to a
      >multiline
      >textbox. Basically, I have created an array of strings which I want to
      >"paste" into a multiline textbox. Any ideas?
      >>
      >--
      >Anil Guptewww.keenin c.netwww.icinem a.com
      >
      You mean something like this:
      >
      //////////////
      Dim strings As String() = {"one", "two", "three", "four"}
      >
      For Each s As String In strings
      Me.TextBox1.Tex t += s
      Me.TextBox1.Tex t += Environment.New Line
      Next
      //////////////
      >
      Thanks,
      >
      Seth Rowe
      >

      Comment

      • Phill W.

        #4
        Re: Writing to a Multiline Textbox programmaticall y

        Anil Gupte wrote:
        That does seem to work. Here is what I tried:
        >
        Dim strLine As String
        Dim n As Integer = 0
        For Each strLine In AllLines
        txtBoxSliceInfo All(n) = strLine
        n = n + 1
        Next strLine
        >
        Just curious as to why that did not work
        Did it even /compile/?
        If so, set Option Strict On at once!

        I couldn't get this to compile; apparently, "you can't index
        txtBoxSliceInfo All because it has no default property", nor do TextBoxes
        expose a property that is an array of strings making up their multi-line
        content.

        Build the string up with Environment.New Line wherever you need a Line
        break, just as Seth showed you:

        For Each sLine As String In AllLines
        txtBoxSliceInfo All.Text = txtBoxSliceInfo All.Text _
        & sLine & Environment.New Line
        Next

        or even more succinctly:

        txtBoxSliceInfo All.Text = String.Join( vbCrLf, AllLines )

        HTH,
        Phill W.

        Comment

        • Anil Gupte

          #5
          Re: Writing to a Multiline Textbox programmaticall y

          Thanx!

          --
          Anil Gupte



          "Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
          news:fc3cf9$fv8 $1@south.jnrs.j a.net...
          Anil Gupte wrote:
          >That does seem to work. Here is what I tried:
          >>
          >Dim strLine As String
          >Dim n As Integer = 0
          >For Each strLine In AllLines
          > txtBoxSliceInfo All(n) = strLine
          > n = n + 1
          >Next strLine
          >>
          >Just curious as to why that did not work
          >
          Did it even /compile/?
          If so, set Option Strict On at once!
          >
          I couldn't get this to compile; apparently, "you can't index
          txtBoxSliceInfo All because it has no default property", nor do TextBoxes
          expose a property that is an array of strings making up their multi-line
          content.
          >
          Build the string up with Environment.New Line wherever you need a Line
          break, just as Seth showed you:
          >
          For Each sLine As String In AllLines
          txtBoxSliceInfo All.Text = txtBoxSliceInfo All.Text _
          & sLine & Environment.New Line
          Next
          >
          or even more succinctly:
          >
          txtBoxSliceInfo All.Text = String.Join( vbCrLf, AllLines )
          >
          HTH,
          Phill W.

          Comment

          • Stephany Young

            #6
            Re: Writing to a Multiline Textbox programmaticall y

            A word of warning.

            Once your 'string' gets reasonably large then setting the Text property of
            the TextBox control is quite slow and after doing so the content is
            'positioned' at the start.

            The next question is usually, how do I move to the end off the text in my
            textbox programatically .

            After setting the Text Property of the TextBox you could always execute:

            TextBox.Selecti onStart = TextBox.TextLen gth
            TextBox.ScrollT oCaret

            A better way of adding multiline data to a multiline TextBox is to use the
            AppendText method. When you use this method the content automatically
            scrolls to the end. The only drawback is that you habe add the NewLine
            yourself:

            TextBox.AppendT ext("Some text." & Environment.New Line)

            This makes it very easy to use a multiline textbox as an on screen 'logging'
            mechanism.



            "Anil Gupte" <anil-list@icinema.co mwrote in message
            news:OvryAoe9HH A.5360@TK2MSFTN GP03.phx.gbl...
            Thanx!
            >
            --
            Anil Gupte


            >
            "Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
            news:fc3cf9$fv8 $1@south.jnrs.j a.net...
            >Anil Gupte wrote:
            >>That does seem to work. Here is what I tried:
            >>>
            >>Dim strLine As String
            >>Dim n As Integer = 0
            >>For Each strLine In AllLines
            >> txtBoxSliceInfo All(n) = strLine
            >> n = n + 1
            >>Next strLine
            >>>
            >>Just curious as to why that did not work
            >>
            >Did it even /compile/?
            >If so, set Option Strict On at once!
            >>
            >I couldn't get this to compile; apparently, "you can't index
            >txtBoxSliceInf oAll because it has no default property", nor do TextBoxes
            >expose a property that is an array of strings making up their multi-line
            >content.
            >>
            >Build the string up with Environment.New Line wherever you need a Line
            >break, just as Seth showed you:
            >>
            >For Each sLine As String In AllLines
            > txtBoxSliceInfo All.Text = txtBoxSliceInfo All.Text _
            > & sLine & Environment.New Line
            >Next
            >>
            >or even more succinctly:
            >>
            >txtBoxSliceInf oAll.Text = String.Join( vbCrLf, AllLines )
            >>
            >HTH,
            > Phill W.
            >
            >

            Comment

            • Anil Gupte

              #7
              Re: Writing to a Multiline Textbox programmaticall y

              Thanx, I am going to save this message and try using it later. Since we are
              on the subject, how about this little problem. Occassionally, I want to
              have the entire text highlighted so the users can jut start typing and
              replace the text. I could not figure out how to do that.

              --
              Anil Gupte



              "Stephany Young" <noone@localhos twrote in message
              news:erZDDmf9HH A.4180@TK2MSFTN GP05.phx.gbl...
              >A word of warning.
              >
              Once your 'string' gets reasonably large then setting the Text property of
              the TextBox control is quite slow and after doing so the content is
              'positioned' at the start.
              >
              The next question is usually, how do I move to the end off the text in my
              textbox programatically .
              >
              After setting the Text Property of the TextBox you could always execute:
              >
              TextBox.Selecti onStart = TextBox.TextLen gth
              TextBox.ScrollT oCaret
              >
              A better way of adding multiline data to a multiline TextBox is to use the
              AppendText method. When you use this method the content automatically
              scrolls to the end. The only drawback is that you habe add the NewLine
              yourself:
              >
              TextBox.AppendT ext("Some text." & Environment.New Line)
              >
              This makes it very easy to use a multiline textbox as an on screen
              'logging' mechanism.
              >
              >
              >
              "Anil Gupte" <anil-list@icinema.co mwrote in message
              news:OvryAoe9HH A.5360@TK2MSFTN GP03.phx.gbl...
              >Thanx!
              >>
              >--
              >Anil Gupte
              >www.keeninc.net
              >www.icinema.com
              >>
              >"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
              >news:fc3cf9$fv 8$1@south.jnrs. ja.net...
              >>Anil Gupte wrote:
              >>>That does seem to work. Here is what I tried:
              >>>>
              >>>Dim strLine As String
              >>>Dim n As Integer = 0
              >>>For Each strLine In AllLines
              >>> txtBoxSliceInfo All(n) = strLine
              >>> n = n + 1
              >>>Next strLine
              >>>>
              >>>Just curious as to why that did not work
              >>>
              >>Did it even /compile/?
              >>If so, set Option Strict On at once!
              >>>
              >>I couldn't get this to compile; apparently, "you can't index
              >>txtBoxSliceIn foAll because it has no default property", nor do TextBoxes
              >>expose a property that is an array of strings making up their multi-line
              >>content.
              >>>
              >>Build the string up with Environment.New Line wherever you need a Line
              >>break, just as Seth showed you:
              >>>
              >>For Each sLine As String In AllLines
              >> txtBoxSliceInfo All.Text = txtBoxSliceInfo All.Text _
              >> & sLine & Environment.New Line
              >>Next
              >>>
              >>or even more succinctly:
              >>>
              >>txtBoxSliceIn foAll.Text = String.Join( vbCrLf, AllLines )
              >>>
              >>HTH,
              >> Phill W.
              >>
              >>
              >

              Comment

              • Stephany Young

                #8
                Re: Writing to a Multiline Textbox programmaticall y

                Have a look at the TextBox.SelectA ll() method.


                "Anil Gupte" <anil-list@icinema.co mwrote in message
                news:OGfbLyg9HH A.4712@TK2MSFTN GP04.phx.gbl...
                Thanx, I am going to save this message and try using it later. Since we
                are on the subject, how about this little problem. Occassionally, I want
                to have the entire text highlighted so the users can jut start typing and
                replace the text. I could not figure out how to do that.
                >
                --
                Anil Gupte


                >
                "Stephany Young" <noone@localhos twrote in message
                news:erZDDmf9HH A.4180@TK2MSFTN GP05.phx.gbl...
                >>A word of warning.
                >>
                >Once your 'string' gets reasonably large then setting the Text property
                >of the TextBox control is quite slow and after doing so the content is
                >'positioned' at the start.
                >>
                >The next question is usually, how do I move to the end off the text in my
                >textbox programatically .
                >>
                >After setting the Text Property of the TextBox you could always execute:
                >>
                > TextBox.Selecti onStart = TextBox.TextLen gth
                > TextBox.ScrollT oCaret
                >>
                >A better way of adding multiline data to a multiline TextBox is to use
                >the AppendText method. When you use this method the content automatically
                >scrolls to the end. The only drawback is that you habe add the NewLine
                >yourself:
                >>
                > TextBox.AppendT ext("Some text." & Environment.New Line)
                >>
                >This makes it very easy to use a multiline textbox as an on screen
                >'logging' mechanism.
                >>
                >>
                >>
                >"Anil Gupte" <anil-list@icinema.co mwrote in message
                >news:OvryAoe9H HA.5360@TK2MSFT NGP03.phx.gbl.. .
                >>Thanx!
                >>>
                >>--
                >>Anil Gupte
                >>www.keeninc.net
                >>www.icinema.com
                >>>
                >>"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
                >>news:fc3cf9$f v8$1@south.jnrs .ja.net...
                >>>Anil Gupte wrote:
                >>>>That does seem to work. Here is what I tried:
                >>>>>
                >>>>Dim strLine As String
                >>>>Dim n As Integer = 0
                >>>>For Each strLine In AllLines
                >>>> txtBoxSliceInfo All(n) = strLine
                >>>> n = n + 1
                >>>>Next strLine
                >>>>>
                >>>>Just curious as to why that did not work
                >>>>
                >>>Did it even /compile/?
                >>>If so, set Option Strict On at once!
                >>>>
                >>>I couldn't get this to compile; apparently, "you can't index
                >>>txtBoxSliceI nfoAll because it has no default property", nor do
                >>>TextBoxes expose a property that is an array of strings making up their
                >>>multi-line content.
                >>>>
                >>>Build the string up with Environment.New Line wherever you need a Line
                >>>break, just as Seth showed you:
                >>>>
                >>>For Each sLine As String In AllLines
                >>> txtBoxSliceInfo All.Text = txtBoxSliceInfo All.Text _
                >>> & sLine & Environment.New Line
                >>>Next
                >>>>
                >>>or even more succinctly:
                >>>>
                >>>txtBoxSliceI nfoAll.Text = String.Join( vbCrLf, AllLines )
                >>>>
                >>>HTH,
                >>> Phill W.
                >>>
                >>>
                >>
                >
                >

                Comment

                Working...