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

change text property to various textbox

P: n/a
how do i change the text property to a lot of textbox if all textbox are
calle textbox1, textbox2 .... instead of doing it one bye one, i mean
something like

for i as integer = 0 to 10

textbox & i .text = i

next i
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 28 May 2008 19:46:00 -0700, Sergio
<Se****@discussions.microsoft.comwrote:
>how do i change the text property to a lot of textbox if all textbox are
calle textbox1, textbox2 .... instead of doing it one bye one, i mean
something like

for i as integer = 0 to 10

textbox & i .text = i

next i
If they are all children of a form or some other container:

For Each ctl As Control In Me.Controls
If ctl Is Textbox Then ' This will do all textboxes
ctl.Text = "something"
End If
Next
Jun 27 '08 #2

P: n/a
Sergio wrote:
how do i change the text property to a lot of textbox if all textbox are
calle textbox1, textbox2 .... instead of doing it one bye one, i mean
something like

for i as integer = 0 to 10
textbox & i .text = i
next i
You don't.
Finding Controls by name is a pain in .Net. Far better to use the
facilities of the [new] language.

Use a list of TextBoxes, load each of your individual TextBoxes (each
with its own, /meaningful/ name) into it, then loop through the list, as
in:

Private tbList As New ArrayList
' VB'2005 and later can use "List(Of TextBox)"

Sub New()
InitializeControls()

tbList.Add( textbox1 )
tbList.Add( textbox2 )
. . .
End Sub

Sub Button1_Click( ... ) Handles Button1.Click
For Each tb as TextBox in tbList
tb.Text = ""
Next
' or, from your example
For iSub as Integer = 0 To tbList.Count - 1
tbList( iSub ).Text = iSub.ToString()
Next
End Sub

HTH,
Phill W.
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.