Home All Groups Group Topic Archive Search About

control array question for VB.Net 2005

Author
8 May 2006 7:06 PM
Rich
Hello,

I have an application that contains several checkboxes.  I originally
created this app in VB.Net 2003 and upgraded the app to VB.Net 2005.  I
understand the vb2005 supports control arrays.  Is this correct?  If so, I
would like to convert my checkboxes to a control array, but without having to
recreate them from scratch because their placement was a real pain.  Is it
possible to go to the property sheet of each checkbox and assign it a
position in the control array?  like checkbox0 would be chk(0), and checkbox1
would be chk(1).  Am I doing this correctly?

Thanks,
Rich

Author
8 May 2006 7:20 PM
Chris
Rich wrote:
> Hello,
>
> I have an application that contains several checkboxes.  I originally
> created this app in VB.Net 2003 and upgraded the app to VB.Net 2005.  I
> understand the vb2005 supports control arrays.  Is this correct?  If so, I
> would like to convert my checkboxes to a control array, but without having to
> recreate them from scratch because their placement was a real pain.  Is it
> possible to go to the property sheet of each checkbox and assign it a
> position in the control array?  like checkbox0 would be chk(0), and checkbox1
> would be chk(1).  Am I doing this correctly?
>
> Thanks,
> Rich

I'm a bit confused on what you are trying to do.  You could always go:

Dim Arr(10) as Array
Arr(0) = CheckBox1

That being said you could do this at the begining of your form load and
then have your control array without changing the declaration of the
controls.

Chris
Author
8 May 2006 8:27 PM
Rich
Thanks for your reply.  Actually, I did do the array thing.  Then I tried to
overload the OnEnter event of the controls (actually for textboxes, which is
where I was going to go next with the control array thing).  Here is what I
have so far:

Dim arrCtrl As Control()

Private Sub From1_Load(...)
arrCtrl = New TextBox(){txt1, txt2, txt3}
....
End Sub

Private Overloads Sub OnEnter(ByVal sender As System.Object, _
                                    ByVal e As System.EventArgs) Handles
arrCtlr().enter
MessageBox.Show("Textbox " & CType(sender, TextBox).Name)
End Sub

I have a problem with ...Handles arrCtlr().Enter
I have tried ...Handles arrCtlr.Enter but I get an error message that says
something about needing to use WithEvents.  What is the correct syntax for
passing an array of controls to an overloaded Event procedure?

Thanks,
Rich


Show quoteHide quote
"Chris" wrote:

> Rich wrote:
> > Hello,
> >
> > I have an application that contains several checkboxes.  I originally
> > created this app in VB.Net 2003 and upgraded the app to VB.Net 2005.  I
> > understand the vb2005 supports control arrays.  Is this correct?  If so, I
> > would like to convert my checkboxes to a control array, but without having to
> > recreate them from scratch because their placement was a real pain.  Is it
> > possible to go to the property sheet of each checkbox and assign it a
> > position in the control array?  like checkbox0 would be chk(0), and checkbox1
> > would be chk(1).  Am I doing this correctly?
> >
> > Thanks,
> > Rich
>
> I'm a bit confused on what you are trying to do.  You could always go:
>
> Dim Arr(10) as Array
> Arr(0) = CheckBox1
>
> That being said you could do this at the begining of your form load and
> then have your control array without changing the declaration of the
> controls.
>
> Chris
>
Author
8 May 2006 11:38 PM
ronchese
Write a method to centralize your calls:
    Private Sub HandleEnter(ByVal sender As Object, ByVal e As System.EventArgs)
        '...
    End Sub

Then, for each control in your array, use the AddHandler statement, pointing the Enter event of textbox to that procedure:
    AddHandler Textbox.Enter, AddressOf HandleEnter

When you close the form, call the RemoveHandler statement.

That's all.

[]s
Cesar









Show quoteHide quote
"Rich" <R***@discussions.microsoft.com> wrote in message news:8D689E91-CF44-4BB2-9307-5E3D4BDE0023@microsoft.com...
> Thanks for your reply.  Actually, I did do the array thing.  Then I tried to
> overload the OnEnter event of the controls (actually for textboxes, which is
> where I was going to go next with the control array thing).  Here is what I
> have so far:
>
> Dim arrCtrl As Control()
>
> Private Sub From1_Load(...)
> arrCtrl = New TextBox(){txt1, txt2, txt3}
> ...
> End Sub
>
> Private Overloads Sub OnEnter(ByVal sender As System.Object, _
>                                    ByVal e As System.EventArgs) Handles
> arrCtlr().enter
> MessageBox.Show("Textbox " & CType(sender, TextBox).Name)
> End Sub
>
> I have a problem with ...Handles arrCtlr().Enter
> I have tried ...Handles arrCtlr.Enter but I get an error message that says
> something about needing to use WithEvents.  What is the correct syntax for
> passing an array of controls to an overloaded Event procedure?
>
> Thanks,
> Rich
>
>
> "Chris" wrote:
>
>> Rich wrote:
>> > Hello,
>> >
>> > I have an application that contains several checkboxes.  I originally
>> > created this app in VB.Net 2003 and upgraded the app to VB.Net 2005.  I
>> > understand the vb2005 supports control arrays.  Is this correct?  If so, I
>> > would like to convert my checkboxes to a control array, but without having to
>> > recreate them from scratch because their placement was a real pain.  Is it
>> > possible to go to the property sheet of each checkbox and assign it a
>> > position in the control array?  like checkbox0 would be chk(0), and checkbox1
>> > would be chk(1).  Am I doing this correctly?
>> >
>> > Thanks,
>> > Rich
>>
>> I'm a bit confused on what you are trying to do.  You could always go:
>>
>> Dim Arr(10) as Array
>> Arr(0) = CheckBox1
>>
>> That being said you could do this at the begining of your form load and
>> then have your control array without changing the declaration of the
>> controls.
>>
>> Chris
>>
Author
9 May 2006 4:55 AM
Rich
Thanks.  I sort of get it.  How do I invoke/call  AddHandler?   I enter a
textbox with the mouse.  How does AddHandler get called?  My goal is to avoid
writing the same routine 20 times for 20 textboxes.

Private Sub txt1_OnEnter(...) Handles...

How do I write the Addhandler so I only have one routine for all of my
textboxes?  Thinking outloud here, do I add the AddHandler call in the array?

arrCtl = new Control(){txt1, txt2, txt3}

I don't know how to add the AddHandler call.


Show quoteHide quote
"ronchese" wrote:

> Write a method to centralize your calls:
>     Private Sub HandleEnter(ByVal sender As Object, ByVal e As System.EventArgs)
>         '...
>     End Sub
>
> Then, for each control in your array, use the AddHandler statement, pointing the Enter event of textbox to that procedure:
>     AddHandler Textbox.Enter, AddressOf HandleEnter
>
> When you close the form, call the RemoveHandler statement.
>
> That's all.
>
> []s
> Cesar
>
>
>
>
>
>
>
>
>
> "Rich" <R***@discussions.microsoft.com> wrote in message news:8D689E91-CF44-4BB2-9307-5E3D4BDE0023@microsoft.com...
> > Thanks for your reply.  Actually, I did do the array thing.  Then I tried to
> > overload the OnEnter event of the controls (actually for textboxes, which is
> > where I was going to go next with the control array thing).  Here is what I
> > have so far:
> >
> > Dim arrCtrl As Control()
> >
> > Private Sub From1_Load(...)
> > arrCtrl = New TextBox(){txt1, txt2, txt3}
> > ...
> > End Sub
> >
> > Private Overloads Sub OnEnter(ByVal sender As System.Object, _
> >                                    ByVal e As System.EventArgs) Handles
> > arrCtlr().enter
> > MessageBox.Show("Textbox " & CType(sender, TextBox).Name)
> > End Sub
> >
> > I have a problem with ...Handles arrCtlr().Enter
> > I have tried ...Handles arrCtlr.Enter but I get an error message that says
> > something about needing to use WithEvents.  What is the correct syntax for
> > passing an array of controls to an overloaded Event procedure?
> >
> > Thanks,
> > Rich
> >
> >
> > "Chris" wrote:
> >
> >> Rich wrote:
> >> > Hello,
> >> >
> >> > I have an application that contains several checkboxes.  I originally
> >> > created this app in VB.Net 2003 and upgraded the app to VB.Net 2005.  I
> >> > understand the vb2005 supports control arrays.  Is this correct?  If so, I
> >> > would like to convert my checkboxes to a control array, but without having to
> >> > recreate them from scratch because their placement was a real pain.  Is it
> >> > possible to go to the property sheet of each checkbox and assign it a
> >> > position in the control array?  like checkbox0 would be chk(0), and checkbox1
> >> > would be chk(1).  Am I doing this correctly?
> >> >
> >> > Thanks,
> >> > Rich
> >>
> >> I'm a bit confused on what you are trying to do.  You could always go:
> >>
> >> Dim Arr(10) as Array
> >> Arr(0) = CheckBox1
> >>
> >> That being said you could do this at the begining of your form load and
> >> then have your control array without changing the declaration of the
> >> controls.
> >>
> >> Chris
> >>
Author
9 May 2006 5:17 AM
Rich
I figured it out.

Dim ctl as control()
Private Sub Form_Load(...)
ctl = new ctl(){txt1, txt2, txt3}
Dim txt As TextBox
For Each txt In ctl
   AddHandler txt.Enter, AddressOf HandleEnter
next

Private Sub HandleEnter(...)
   MessageBox.Show(Ctype(sender, TextBox).Name)
End Sub

Show quoteHide quote
"Rich" wrote:

> Thanks.  I sort of get it.  How do I invoke/call  AddHandler?   I enter a
> textbox with the mouse.  How does AddHandler get called?  My goal is to avoid
> writing the same routine 20 times for 20 textboxes.
>
> Private Sub txt1_OnEnter(...) Handles...
>
> How do I write the Addhandler so I only have one routine for all of my
> textboxes?  Thinking outloud here, do I add the AddHandler call in the array?
>
> arrCtl = new Control(){txt1, txt2, txt3}
>
> I don't know how to add the AddHandler call.
>
>
> "ronchese" wrote:
>
> > Write a method to centralize your calls:
> >     Private Sub HandleEnter(ByVal sender As Object, ByVal e As System.EventArgs)
> >         '...
> >     End Sub
> >
> > Then, for each control in your array, use the AddHandler statement, pointing the Enter event of textbox to that procedure:
> >     AddHandler Textbox.Enter, AddressOf HandleEnter
> >
> > When you close the form, call the RemoveHandler statement.
> >
> > That's all.
> >
> > []s
> > Cesar
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > "Rich" <R***@discussions.microsoft.com> wrote in message news:8D689E91-CF44-4BB2-9307-5E3D4BDE0023@microsoft.com...
> > > Thanks for your reply.  Actually, I did do the array thing.  Then I tried to
> > > overload the OnEnter event of the controls (actually for textboxes, which is
> > > where I was going to go next with the control array thing).  Here is what I
> > > have so far:
> > >
> > > Dim arrCtrl As Control()
> > >
> > > Private Sub From1_Load(...)
> > > arrCtrl = New TextBox(){txt1, txt2, txt3}
> > > ...
> > > End Sub
> > >
> > > Private Overloads Sub OnEnter(ByVal sender As System.Object, _
> > >                                    ByVal e As System.EventArgs) Handles
> > > arrCtlr().enter
> > > MessageBox.Show("Textbox " & CType(sender, TextBox).Name)
> > > End Sub
> > >
> > > I have a problem with ...Handles arrCtlr().Enter
> > > I have tried ...Handles arrCtlr.Enter but I get an error message that says
> > > something about needing to use WithEvents.  What is the correct syntax for
> > > passing an array of controls to an overloaded Event procedure?
> > >
> > > Thanks,
> > > Rich
> > >
> > >
> > > "Chris" wrote:
> > >
> > >> Rich wrote:
> > >> > Hello,
> > >> >
> > >> > I have an application that contains several checkboxes.  I originally
> > >> > created this app in VB.Net 2003 and upgraded the app to VB.Net 2005.  I
> > >> > understand the vb2005 supports control arrays.  Is this correct?  If so, I
> > >> > would like to convert my checkboxes to a control array, but without having to
> > >> > recreate them from scratch because their placement was a real pain.  Is it
> > >> > possible to go to the property sheet of each checkbox and assign it a
> > >> > position in the control array?  like checkbox0 would be chk(0), and checkbox1
> > >> > would be chk(1).  Am I doing this correctly?
> > >> >
> > >> > Thanks,
> > >> > Rich
> > >>
> > >> I'm a bit confused on what you are trying to do.  You could always go:
> > >>
> > >> Dim Arr(10) as Array
> > >> Arr(0) = CheckBox1
> > >>
> > >> That being said you could do this at the begining of your form load and
> > >> then have your control array without changing the declaration of the
> > >> controls.
> > >>
> > >> Chris
> > >>
Author
10 May 2006 8:00 PM
ronchese
Yeah!

Show quoteHide quote
:^D


"Rich" <R***@discussions.microsoft.com> wrote in message
news:38326B75-B288-417A-BA01-345306B2FAAD@microsoft.com...
>I figured it out.
>
> Dim ctl as control()
> Private Sub Form_Load(...)
> ctl = new ctl(){txt1, txt2, txt3}
> Dim txt As TextBox
> For Each txt In ctl
>   AddHandler txt.Enter, AddressOf HandleEnter
> next
>
> Private Sub HandleEnter(...)
>   MessageBox.Show(Ctype(sender, TextBox).Name)
> End Sub
>
> "Rich" wrote:
>
>> Thanks.  I sort of get it.  How do I invoke/call  AddHandler?   I enter a
>> textbox with the mouse.  How does AddHandler get called?  My goal is to
>> avoid
>> writing the same routine 20 times for 20 textboxes.
>>
>> Private Sub txt1_OnEnter(...) Handles...
>>
>> How do I write the Addhandler so I only have one routine for all of my
>> textboxes?  Thinking outloud here, do I add the AddHandler call in the
>> array?
>>
>> arrCtl = new Control(){txt1, txt2, txt3}
>>
>> I don't know how to add the AddHandler call.
>>
>>
>> "ronchese" wrote:
>>
>> > Write a method to centralize your calls:
>> >     Private Sub HandleEnter(ByVal sender As Object, ByVal e As
>> > System.EventArgs)
>> >         '...
>> >     End Sub
>> >
>> > Then, for each control in your array, use the AddHandler statement,
>> > pointing the Enter event of textbox to that procedure:
>> >     AddHandler Textbox.Enter, AddressOf HandleEnter
>> >
>> > When you close the form, call the RemoveHandler statement.
>> >
>> > That's all.
>> >
>> > []s
>> > Cesar
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > "Rich" <R***@discussions.microsoft.com> wrote in message
>> > news:8D689E91-CF44-4BB2-9307-5E3D4BDE0023@microsoft.com...
>> > > Thanks for your reply.  Actually, I did do the array thing.  Then I
>> > > tried to
>> > > overload the OnEnter event of the controls (actually for textboxes,
>> > > which is
>> > > where I was going to go next with the control array thing).  Here is
>> > > what I
>> > > have so far:
>> > >
>> > > Dim arrCtrl As Control()
>> > >
>> > > Private Sub From1_Load(...)
>> > > arrCtrl = New TextBox(){txt1, txt2, txt3}
>> > > ...
>> > > End Sub
>> > >
>> > > Private Overloads Sub OnEnter(ByVal sender As System.Object, _
>> > >                                    ByVal e As System.EventArgs)
>> > > Handles
>> > > arrCtlr().enter
>> > > MessageBox.Show("Textbox " & CType(sender, TextBox).Name)
>> > > End Sub
>> > >
>> > > I have a problem with ...Handles arrCtlr().Enter
>> > > I have tried ...Handles arrCtlr.Enter but I get an error message that
>> > > says
>> > > something about needing to use WithEvents.  What is the correct
>> > > syntax for
>> > > passing an array of controls to an overloaded Event procedure?
>> > >
>> > > Thanks,
>> > > Rich
>> > >
>> > >
>> > > "Chris" wrote:
>> > >
>> > >> Rich wrote:
>> > >> > Hello,
>> > >> >
>> > >> > I have an application that contains several checkboxes.  I
>> > >> > originally
>> > >> > created this app in VB.Net 2003 and upgraded the app to VB.Net
>> > >> > 2005.  I
>> > >> > understand the vb2005 supports control arrays.  Is this correct?
>> > >> > If so, I
>> > >> > would like to convert my checkboxes to a control array, but
>> > >> > without having to
>> > >> > recreate them from scratch because their placement was a real
>> > >> > pain.  Is it
>> > >> > possible to go to the property sheet of each checkbox and assign
>> > >> > it a
>> > >> > position in the control array?  like checkbox0 would be chk(0),
>> > >> > and checkbox1
>> > >> > would be chk(1).  Am I doing this correctly?
>> > >> >
>> > >> > Thanks,
>> > >> > Rich
>> > >>
>> > >> I'm a bit confused on what you are trying to do.  You could always
>> > >> go:
>> > >>
>> > >> Dim Arr(10) as Array
>> > >> Arr(0) = CheckBox1
>> > >>
>> > >> That being said you could do this at the begining of your form load
>> > >> and
>> > >> then have your control array without changing the declaration of the
>> > >> controls.
>> > >>
>> > >> Chris
>> > >>