By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,974 Members | 1,834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,974 IT Pros & Developers. It's quick & easy.

Writing to a Multiline Textbox programmatically

P: n/a

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
www.keeninc.net
www.icinema.com
Sep 7 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Sep 7, 7:36 am, "Anil Gupte" <anil-l...@icinema.comwrote:
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.keeninc.netwww.icinema.com
You mean something like this:

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

For Each s As String In strings
Me.TextBox1.Text += s
Me.TextBox1.Text += Environment.NewLine
Next
//////////////

Thanks,

Seth Rowe

Sep 7 '07 #2

P: n/a
That does seem to work. Here is what I tried:

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

Just curious as to why that did not work

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
On Sep 7, 7:36 am, "Anil Gupte" <anil-l...@icinema.comwrote:
>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.keeninc.netwww.icinema.com

You mean something like this:

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

For Each s As String In strings
Me.TextBox1.Text += s
Me.TextBox1.Text += Environment.NewLine
Next
//////////////

Thanks,

Seth Rowe

Sep 7 '07 #3

P: n/a
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
txtBoxSliceInfoAll(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
txtBoxSliceInfoAll 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.NewLine wherever you need a Line
break, just as Seth showed you:

For Each sLine As String In AllLines
txtBoxSliceInfoAll.Text = txtBoxSliceInfoAll.Text _
& sLine & Environment.NewLine
Next

or even more succinctly:

txtBoxSliceInfoAll.Text = String.Join( vbCrLf, AllLines )

HTH,
Phill W.
Sep 10 '07 #4

P: n/a
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:fc**********@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
txtBoxSliceInfoAll(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
txtBoxSliceInfoAll 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.NewLine wherever you need a Line
break, just as Seth showed you:

For Each sLine As String In AllLines
txtBoxSliceInfoAll.Text = txtBoxSliceInfoAll.Text _
& sLine & Environment.NewLine
Next

or even more succinctly:

txtBoxSliceInfoAll.Text = String.Join( vbCrLf, AllLines )

HTH,
Phill W.

Sep 13 '07 #5

P: n/a
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.SelectionStart = TextBox.TextLength
TextBox.ScrollToCaret

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.AppendText("Some text." & Environment.NewLine)

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

"Anil Gupte" <an*******@icinema.comwrote in message
news:Ov**************@TK2MSFTNGP03.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:fc**********@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
txtBoxSliceInfoAll(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
txtBoxSliceInfoAll 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.NewLine wherever you need a Line
break, just as Seth showed you:

For Each sLine As String In AllLines
txtBoxSliceInfoAll.Text = txtBoxSliceInfoAll.Text _
& sLine & Environment.NewLine
Next

or even more succinctly:

txtBoxSliceInfoAll.Text = String.Join( vbCrLf, AllLines )

HTH,
Phill W.

Sep 13 '07 #6

P: n/a
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
www.keeninc.net
www.icinema.com

"Stephany Young" <noone@localhostwrote in message
news:er**************@TK2MSFTNGP05.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.SelectionStart = TextBox.TextLength
TextBox.ScrollToCaret

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.AppendText("Some text." & Environment.NewLine)

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

"Anil Gupte" <an*******@icinema.comwrote in message
news:Ov**************@TK2MSFTNGP03.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:fc**********@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
txtBoxSliceInfoAll(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
txtBoxSliceInfoAll 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.NewLine wherever you need a Line
break, just as Seth showed you:

For Each sLine As String In AllLines
txtBoxSliceInfoAll.Text = txtBoxSliceInfoAll.Text _
& sLine & Environment.NewLine
Next

or even more succinctly:

txtBoxSliceInfoAll.Text = String.Join( vbCrLf, AllLines )

HTH,
Phill W.


Sep 13 '07 #7

P: n/a
Have a look at the TextBox.SelectAll() method.
"Anil Gupte" <an*******@icinema.comwrote in message
news:OG**************@TK2MSFTNGP04.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
www.keeninc.net
www.icinema.com

"Stephany Young" <noone@localhostwrote in message
news:er**************@TK2MSFTNGP05.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.SelectionStart = TextBox.TextLength
TextBox.ScrollToCaret

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.AppendText("Some text." & Environment.NewLine)

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

"Anil Gupte" <an*******@icinema.comwrote in message
news:Ov**************@TK2MSFTNGP03.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:fc**********@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
txtBoxSliceInfoAll(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
txtBoxSliceInfoAll 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.NewLine wherever you need a Line
break, just as Seth showed you:

For Each sLine As String In AllLines
txtBoxSliceInfoAll.Text = txtBoxSliceInfoAll.Text _
& sLine & Environment.NewLine
Next

or even more succinctly:

txtBoxSliceInfoAll.Text = String.Join( vbCrLf, AllLines )

HTH,
Phill W.


Sep 13 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.