Make a loop in the array of text boxes; in this loop, add an event handler to every one; in the event handler, use the same method to deal with the sender, which will be a reference to a particular text box.
If this is just validation, is some cases you won't even need to know a reference to each of the text boxes is passed to the event handling method. However, usually this is needed. The only information you can use is the reference to the sender, passed as a first parameter of the event handler.
First, you can always type-case this reference to
TextBox
, because, in this scenario, this is always the sender. So, you get a reference to an instance of the
TextBox
. To pass additional information, you can use the property
TextBox.Tag
(inherited from
Control.Tag
). In your case, it would be the best to assign an index in your array to this
Tag
. In the event handler, you type-cast
Tag
to
int
and this way know the index of the array element being handled.
[EDIT]
I almost forgot, VB.NET does not have '+=' operator for adding a handler to an invocation list of an event instance. You need to use
AddHandler
. This is shown in a code sample here, see the answer #0:
http://stackoverflow.com/questions/4199370/how-to-create-event-for-dynamic-control-array-in-vb-net[
^].
—SA