473,463 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

control array question for VB.Net 2005

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
May 8 '06 #1
6 3042
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
May 8 '06 #2
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

May 8 '06 #3
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" <Ri**@discussions.microsoft.com> wrote in message news:8D**********************************@microsof t.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

May 8 '06 #4
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" <Ri**@discussions.microsoft.com> wrote in message news:8D**********************************@microsof t.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

May 10 '06 #5
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" <Ri**@discussions.microsoft.com> wrote in message news:8D**********************************@microsof t.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
>

May 10 '06 #6
Yeah!

:^D
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.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" <Ri**@discussions.microsoft.com> wrote in message
> news:8D**********************************@microsof t.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
> >>

May 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
7
by: Tom wilson | last post by:
I'm trying to create dynamic controls in ASP.Net. It's driving me nuts. I keep getting the error: Control '16' of type 'RadioButton' must be placed inside a form tag with runat=server. Dim...
4
by: bienwell | last post by:
Hi all, Data displayed on the datalist control is bound by the column name of the dataset like this : <%# DataBinder.Eval(Container.DataItem, "title")%> Could I use an element of the array...
3
by: Robert | last post by:
How can I declare in VB .NET an array of labels for example and afterwards using a FOR structure load every component of the array? I've used this code but it doesn't work: dim x(10) as label...
5
by: Diarmuid | last post by:
Are there control arrays in vb.net 2005? Maybe some one could help me out with an example. I know how to this in VB6. My database is called Planner.mdb There is a table called Weekdays. I want to...
4
by: bis | last post by:
In the 7 November 2005 final "Visual Studio 2005" release called Whidbey (if I'm not wrong), will we have the Control Array back ? Time ago someone said no, then time later someother said...
9
by: Michael D. Ober | last post by:
In VB 6, you can create control arrays for your option groups and scan with the following code dim opt as OptionButton for each opt in OptionGroup ' Do something next opt I know VB 2005...
4
by: Arne Beruldsen | last post by:
I'm a recent convert to VB.net from VB6...and I can't believe they don't support control arrays. I have an app that uses a ton of Control Arrays...mostly labels and text boxes. I need some...
2
by: deccio | last post by:
I have create an activex Control with Visual studio 2005 and framework 2.0 in c# to add drag & drop functionality to upload multi file. When I use it in a windows form it work fine. Infact if I...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.