|
-
Apr 7th, 2002, 12:34 PM
#1
Thread Starter
Junior Member
Loading information into text boxes
Is there a way to "automatically" load values into a multitude of text boxes in VB.Net?
In version 6, we did this by using the text boxes’ index numbers in a loop.
I am aware of the tabindex that is available in .Net, but if changes are made to the forms the controls might no longer be indexed contiguously.
Please let me know if anyone has a suggestion.
Terje
-
Apr 8th, 2002, 07:04 AM
#2
Hyperactive Member
You could iterate through the forms control collection
-
Apr 9th, 2002, 09:16 AM
#3
Thread Starter
Junior Member
Collection
Bananafish, thanks for your reply.
Could you elaborate a little on your question?
Thanks
Terje
-
Apr 9th, 2002, 10:32 AM
#4
Frenzied Member
You can also use the ParamArray feature:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ChangeTextBoxes("Hello", TextBox1, TextBox2, TextBox3)
End Sub
Private Sub ChangeTextBoxes(ByVal sText As String, ByVal ParamArray textboxes() As TextBox)
Dim x As Integer
For x = 0 To textboxes.Length - 1
textboxes(x).Text = sText
Next
End Sub
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Apr 9th, 2002, 11:19 AM
#5
Hyperactive Member
this is the Control Collection way. Horses for courses I guess...
VB Code:
Dim oCtr As System.Windows.Forms.Control
For Each oCtr In Me.Controls
If oCtr.GetType.Name = "TextBox" Then
If oCtr.Name.StartsWith("txtAutoLoad") Then
'do whatever
txtAutoLoadA.Text = "aaa"
txtAutoLoadB.Text = "bbb"
End If
End If
Next
-
Apr 9th, 2002, 11:29 AM
#6
Thread Starter
Junior Member
Thanks for all your help.
Terje
-
Apr 9th, 2002, 11:40 AM
#7
Hyperactive Member
Actually - to be more dynamic the following code is better
VB Code:
Dim oCtr As System.Windows.Forms.Control
Dim oTxt As System.Windows.Forms.TextBox
For Each oCtr In Me.Controls
If oCtr.GetType.Name = "TextBox" Then
If oCtr.Name.StartsWith("txtAutoLoad") Then
'do whatever
oTxt = CType(oCtr, TextBox)
oTxt.Text = "aaa"
End If
End If
Next
-
Apr 18th, 2002, 07:42 AM
#8
What kind of performance hit can this create? I have a form that has over 200 label controls, In VB6 it was easy using a control array, and an array to hold the values, and setting the value was as simple as using the same index for the control ans the underlying value in the array. In .Net I am forced into calling a routine that itterates through the controls collection.
Is ther a way if I know the name of the control to find it, or set it quicker?, I dont really want to have to be stepping through the collection every time to find the correct control?
Control arrays are the one thing I wish they had kept.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|