TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

Writing to a Multiline Textbox programmatically

VB.NET

 
 
Thread Tools Display Modes
Unread 07-09-2007, 12:03 PM   #1
Anil Gupte
Guest
 
Posts: n/a
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
www.keeninc.net
www.icinema.com


 
Unread 07-09-2007, 01:02 PM   #2
rowe_newsgroups
Guest
 
Posts: n/a
Re: Writing to a Multiline Textbox programmatically

On Sep 7, 7:36 am, "Anil Gupte" <anil-l...@icinema.com> wrote:
> 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

 
Unread 07-09-2007, 05:02 PM   #3
Anil Gupte
Guest
 
Posts: n/a
Re: Writing to a Multiline Textbox programmatically

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" <rowe_email***********> wrote in message
news:1189167481.805733.205040@19g2000hsx.googlegro ups.com...
> On Sep 7, 7:36 am, "Anil Gupte" <anil-l...@icinema.com> wrote:
>> 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
>



 
Unread 10-09-2007, 03:19 PM   #4
Phill W.
Guest
 
Posts: n/a
Re: Writing to a Multiline Textbox programmatically

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.
 
Unread 15-09-2007, 05:06 AM   #5
Anil Gupte
Guest
 
Posts: n/a
Re: Writing to a Multiline Textbox programmatically

Thanx!

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

"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-k> wrote in message
news:fc3cf9$fv8$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
>> 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.



 
Unread 15-09-2007, 05:07 AM   #6
Stephany Young
Guest
 
Posts: n/a
Re: Writing to a Multiline Textbox programmatically

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" <anil-list@icinema.com> wrote in message
news:OvryAoe9HHA.5360@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-k> wrote in message
> news:fc3cf9$fv8$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
>>> 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.

>
>


 
Unread 15-09-2007, 05:07 AM   #7
Anil Gupte
Guest
 
Posts: n/a
Re: Writing to a Multiline Textbox programmatically

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@localhost> wrote in message
news:erZDDmf9HHA.4180@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" <anil-list@icinema.com> wrote in message
> news:OvryAoe9HHA.5360@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-k> wrote in message
>> news:fc3cf9$fv8$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
>>>> 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.

>>
>>

>



 
Unread 15-09-2007, 05:08 AM   #8
Stephany Young
Guest
 
Posts: n/a
Re: Writing to a Multiline Textbox programmatically

Have a look at the TextBox.SelectAll() method.


"Anil Gupte" <anil-list@icinema.com> wrote in message
news:OGfbLyg9HHA.4712@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@localhost> wrote in message
> news:erZDDmf9HHA.4180@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" <anil-list@icinema.com> wrote in message
>> news:OvryAoe9HHA.5360@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-k> wrote in message
>>> news:fc3cf9$fv8$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
>>>>> 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.
>>>
>>>

>>

>
>


 
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying MultiLine Content in a TextBox zacks@construction-imaging.com C#(C Sharp) 4 06-09-2007 04:01 PM
Re: Programmatically lock down an account Joe Richards [MVP] Windows Server 2003 2 27-08-2007 11:07 PM
Re: Programmatically lock down an account Joe Richards [MVP] Windows Server 2003 2 27-08-2007 11:05 PM
Detect 3GB switch programmatically scorpneo@gmail.com Windows Vista All 0 17-08-2007 10:16 AM
Detect 3GB switch programmatically scorpneo@gmail.com Windows XP 2 16-08-2007 05:47 AM


< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 01:11 PM.


vBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2013, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional