Tuesday, March 13, 2012

Textbox array?

I've started using VB.net instead of VB6. I'm missing the possiblity of making textboxes as an array. In VB6 this is standard, but is it possible at all in VB.Net?There are no control arrays in .net like there was in VB6.

What is it your trying to do?
to make a control array in .NET you create for example 3 textboxes named text1,text2,text3 respectively. Then in the text1 change event(Or any event) where it says Handles you append the extra textbox names and events.

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged

I havnet figured out how to detect which textbox was used, but this fires the event for all 3 textboxes.
I havnet figured out how to detect which textbox was used, but this fires the event for all 3 textboxes.

The way to figure out which one is to cast the sender object to a textbox, then refer to the senders name.

Dim myTextBox As TextBox
myTextBox = CType(sender, TextBox)

If myTextBox.Name = TextBox1 Then
' Do your processing for textbox 1.
End If

If myTextBox.Name = TextBox2 Then
' Do your processing for textbox 2.
End If
I have a this sub:

Private Sub btnNulstil_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNulstil.Click
txtKar1.Text = ""
txtKar2.Text = ""
txtKar3.Text = ""
txtKar4.Text = ""
txtKar5.Text = ""
End Sub

Imagine that I had 100 text boxes, I would'nt like to write the lines txtKarX.text ="" up to 100. How can I make this in a smart way?
good question.. and i have no earthly idea why microsoft got rid of control arrays.

But i would think you would loop thru them using some sort of Object collection thingy.

0 comments:

Post a Comment