Connecting Tech Pros Worldwide Help | Site Map

Runtime, array of controls events

vbMark
Guest
 
Posts: n/a
#1: Nov 21 '05
I have the following code:

Dim myTextBox(10) As TextBox

Dim x As Integer
For x = 0 To 9

myTextBox(x) = New TextBox
With myTextBox(x)
Select Case x
Pipo
Guest
 
Posts: n/a
#2: Nov 21 '05

re: Runtime, array of controls events


Hi vbMark,

I dont see the events OnFocus or Onchange for a textbox.
But in general you create an addhandler for the events you'll need.

Hope this helps


"vbMark" <no@email.com> wrote in message
news:Xns95E162A4145A8noemailcom@130.133.1.4...[color=blue]
> I have the following code:
>
> Dim myTextBox(10) As TextBox
>
> Dim x As Integer
> For x = 0 To 9
>
> myTextBox(x) = New TextBox
> With myTextBox(x)
> Select Case x
> .
> . some code
> .
> End Select
> End With
>
> Me.Controls.Add(myTextBox(x))
>
> Next
>
> Now how do I get the OnFocus or OnChange events for myTextBox?
>
> Thanks![/color]


vbMark
Guest
 
Posts: n/a
#3: Nov 21 '05

re: Runtime, array of controls events


Sorry, I meant GotFocus and TextChanged.


"Pipo" <Pipo@nobody.com> wrote in news:OkBwTPK$EHA.3988
@TK2MSFTNGP11.phx.gbl:
[color=blue]
> Hi vbMark,
>
> I dont see the events OnFocus or Onchange for a textbox.
> But in general you create an addhandler for the events you'll need.
>
> Hope this helps
>
>
> "vbMark" <no@email.com> wrote in message
> news:Xns95E162A4145A8noemailcom@130.133.1.4...[color=green]
>> I have the following code:
>>
>> Dim myTextBox(10) As TextBox
>>
>> Dim x As Integer
>> For x = 0 To 9
>>
>> myTextBox(x) = New TextBox
>> With myTextBox(x)
>> Select Case x
>> .
>> . some code
>> .
>> End Select
>> End With
>>
>> Me.Controls.Add(myTextBox(x))
>>
>> Next
>>
>> Now how do I get the OnFocus or OnChange events for myTextBox?
>>
>> Thanks![/color]
>
>
>[/color]

Pipo
Guest
 
Posts: n/a
#4: Nov 21 '05

re: Runtime, array of controls events


Hi vbMark,

Did you looked at addhandler?
Is your problem solved?

Greets,


"vbMark" <no@email.com> wrote in message
news:Xns95E1666955C4Anoemailcom@130.133.1.4...[color=blue]
> Sorry, I meant GotFocus and TextChanged.
>
>
> "Pipo" <Pipo@nobody.com> wrote in news:OkBwTPK$EHA.3988
> @TK2MSFTNGP11.phx.gbl:
>[color=green]
> > Hi vbMark,
> >
> > I dont see the events OnFocus or Onchange for a textbox.
> > But in general you create an addhandler for the events you'll need.
> >
> > Hope this helps
> >
> >
> > "vbMark" <no@email.com> wrote in message
> > news:Xns95E162A4145A8noemailcom@130.133.1.4...[color=darkred]
> >> I have the following code:
> >>
> >> Dim myTextBox(10) As TextBox
> >>
> >> Dim x As Integer
> >> For x = 0 To 9
> >>
> >> myTextBox(x) = New TextBox
> >> With myTextBox(x)
> >> Select Case x
> >> .
> >> . some code
> >> .
> >> End Select
> >> End With
> >>
> >> Me.Controls.Add(myTextBox(x))
> >>
> >> Next
> >>
> >> Now how do I get the OnFocus or OnChange events for myTextBox?
> >>
> >> Thanks![/color]
> >
> >
> >[/color]
>[/color]


Cor Ligthert
Guest
 
Posts: n/a
#5: Nov 21 '05

re: Runtime, array of controls events


vbMark

\\\
For Each ctr as TextBox In myTextBox
AddHandler ctr.GotFocus, AddressOf meGotFocus
AddHandler ctr.TextChanged, AddressOf meTextChanged
Next
///

I hope this helps?

Cor



vbMark
Guest
 
Posts: n/a
#6: Nov 21 '05

re: Runtime, array of controls events


I think addhandler may be what I'm looking for. First tests look good.
I'll contine trying it out.

Thanks!

"Pipo" <Pipo@nobody.com> wrote in news:ODc12ZK$EHA.1084
@tk2msftngp13.phx.gbl:
[color=blue]
> Hi vbMark,
>
> Did you looked at addhandler?
> Is your problem solved?
>
> Greets,
>
>
> "vbMark" <no@email.com> wrote in message
> news:Xns95E1666955C4Anoemailcom@130.133.1.4...[color=green]
>> Sorry, I meant GotFocus and TextChanged.
>>
>>
>> "Pipo" <Pipo@nobody.com> wrote in news:OkBwTPK$EHA.3988
>> @TK2MSFTNGP11.phx.gbl:
>>[color=darkred]
>> > Hi vbMark,
>> >
>> > I dont see the events OnFocus or Onchange for a textbox.
>> > But in general you create an addhandler for the events you'll need.
>> >
>> > Hope this helps
>> >
>> >
>> > "vbMark" <no@email.com> wrote in message
>> > news:Xns95E162A4145A8noemailcom@130.133.1.4...
>> >> I have the following code:
>> >>
>> >> Dim myTextBox(10) As TextBox
>> >>
>> >> Dim x As Integer
>> >> For x = 0 To 9
>> >>
>> >> myTextBox(x) = New TextBox
>> >> With myTextBox(x)
>> >> Select Case x
>> >> .
>> >> . some code
>> >> .
>> >> End Select
>> >> End With
>> >>
>> >> Me.Controls.Add(myTextBox(x))
>> >>
>> >> Next
>> >>
>> >> Now how do I get the OnFocus or OnChange events for myTextBox?
>> >>
>> >> Thanks!
>> >
>> >
>> >[/color]
>>[/color]
>
>
>[/color]

vbMark
Guest
 
Posts: n/a
#7: Nov 21 '05

re: Runtime, array of controls events


"Cor Ligthert" <notmyfirstname@planet.nl> wrote in news:#WKBRfK$EHA.3820
@TK2MSFTNGP11.phx.gbl:
[color=blue]
> vbMark
>
> \\\
> For Each ctr as TextBox In myTextBox
> AddHandler ctr.GotFocus, AddressOf meGotFocus
> AddHandler ctr.TextChanged, AddressOf meTextChanged
> Next
> ///
>
> I hope this helps?
>
> Cor
>
>[/color]

Ok, using AddHandler works and creates the event. Now how do I know which
control in the array fired the event?

I have this in my loop:
AddHandler myTextBox(x).GotFocus, AddressOf myTextBox_GotFocus

And this Sub:
Sub myTextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
????
End Sub

Thanks.

Cor Ligthert
Guest
 
Posts: n/a
#8: Nov 21 '05

re: Runtime, array of controls events


vbMark,

In this situation I gave every control a name before I add them to the form.

\\\
myTextBox.Name=x.ToString
Me.Controls.Add(myTextBox(x))
///

Then you can do by instance in the event

\\\
Sub myTextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case DirectCast(sender,TextBox).Name
Case "0"
'do something
Case "1"
End Sub
///

I hope this helps?

Cor


vbMark
Guest
 
Posts: n/a
#9: Nov 21 '05

re: Runtime, array of controls events


Excellent! Thanks!

"Cor Ligthert" <notmyfirstname@planet.nl> wrote in
news:#zIyU8L$EHA.3988@TK2MSFTNGP11.phx.gbl:
[color=blue]
> vbMark,
>
> In this situation I gave every control a name before I add them to the
> form.
>
> \\\
> myTextBox.Name=x.ToString
> Me.Controls.Add(myTextBox(x))
> ///
>
> Then you can do by instance in the event
>
> \\\
> Sub myTextBox_GotFocus(ByVal sender As Object, ByVal e As
> System.EventArgs)
> Select Case DirectCast(sender,TextBox).Name
> Case "0"
> 'do something
> Case "1"
> End Sub
> ///
>
> I hope this helps?
>
> Cor
>
>
>[/color]

Closed Thread