Why are there no form control arrays in vb.net?
-
I have a large application in VB6 which makes extensive use of control arrays as they are so easily used and referenced by the index value With future support disappearing after win7 I am trying to code extensions in a way that will make the eventual transfer to vb.net easier but faced with a form that has 4 groups of 10 simple list combo boxes that need to be set at runtime and then saved after the user has selected their content all the alternatives to control arrays significantly increase the amount of typing that I have to do and therefore the opportunity for a typo that compiles (each control is called cmbCAtab1, cmbCAtab2 etc which is easy for cut and paste but easier to miss changing one of the names afterwards and it would still compile) Would it really hurt VB.net so much to have Control Arrays which it seams to me were quite a simple way of handling things I appreciate there are ways to combine the event handlers and to set and read the "array" of controls in VB.net but WHY should I have to jump through all the extra hoops when I should just be able to use an index value??? It would also help VB6 applications move to VB.net which I would have thought was part of the aim of the .net version developers Gets under desk and puts fingers in ears, ok people fire away!
-
I have a large application in VB6 which makes extensive use of control arrays as they are so easily used and referenced by the index value With future support disappearing after win7 I am trying to code extensions in a way that will make the eventual transfer to vb.net easier but faced with a form that has 4 groups of 10 simple list combo boxes that need to be set at runtime and then saved after the user has selected their content all the alternatives to control arrays significantly increase the amount of typing that I have to do and therefore the opportunity for a typo that compiles (each control is called cmbCAtab1, cmbCAtab2 etc which is easy for cut and paste but easier to miss changing one of the names afterwards and it would still compile) Would it really hurt VB.net so much to have Control Arrays which it seams to me were quite a simple way of handling things I appreciate there are ways to combine the event handlers and to set and read the "array" of controls in VB.net but WHY should I have to jump through all the extra hoops when I should just be able to use an index value??? It would also help VB6 applications move to VB.net which I would have thought was part of the aim of the .net version developers Gets under desk and puts fingers in ears, ok people fire away!
Mike Deeks wrote:
Would it really hurt VB.net so much to have Control Arrays
Yes, because the concept isn't OOP compliant. VB6 taught way too many bad habits. If you really want control arrays, just throw the controls in a generic collection of them.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
I have a large application in VB6 which makes extensive use of control arrays as they are so easily used and referenced by the index value With future support disappearing after win7 I am trying to code extensions in a way that will make the eventual transfer to vb.net easier but faced with a form that has 4 groups of 10 simple list combo boxes that need to be set at runtime and then saved after the user has selected their content all the alternatives to control arrays significantly increase the amount of typing that I have to do and therefore the opportunity for a typo that compiles (each control is called cmbCAtab1, cmbCAtab2 etc which is easy for cut and paste but easier to miss changing one of the names afterwards and it would still compile) Would it really hurt VB.net so much to have Control Arrays which it seams to me were quite a simple way of handling things I appreciate there are ways to combine the event handlers and to set and read the "array" of controls in VB.net but WHY should I have to jump through all the extra hoops when I should just be able to use an index value??? It would also help VB6 applications move to VB.net which I would have thought was part of the aim of the .net version developers Gets under desk and puts fingers in ears, ok people fire away!
if the Controls are contained in a single Container (a Panel, a GroupBox, ...), you can always use
myContainer.Controls(index)
:)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
if the Controls are contained in a single Container (a Panel, a GroupBox, ...), you can always use
myContainer.Controls(index)
:)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Mike Deeks wrote:
Would it really hurt VB.net so much to have Control Arrays
Yes, because the concept isn't OOP compliant. VB6 taught way too many bad habits. If you really want control arrays, just throw the controls in a generic collection of them.
A guide to posting questions on CodeProject[^]
Dave KreskowiakDave Kreskowiak wrote:
Yes, because the concept isn't OOP complian
so having an array of objects breaks OOP compliancy? I would have looked this up but struggled to find what the definitions are for OOP compliance (yes i did google but got bored after 2 pages of results) mind you, I did see a number of references where people said they had to break OOP compliance to be able to make a particular program work so maybe it is the OOP definition that is wrong?
-
I have a large application in VB6 which makes extensive use of control arrays as they are so easily used and referenced by the index value With future support disappearing after win7 I am trying to code extensions in a way that will make the eventual transfer to vb.net easier but faced with a form that has 4 groups of 10 simple list combo boxes that need to be set at runtime and then saved after the user has selected their content all the alternatives to control arrays significantly increase the amount of typing that I have to do and therefore the opportunity for a typo that compiles (each control is called cmbCAtab1, cmbCAtab2 etc which is easy for cut and paste but easier to miss changing one of the names afterwards and it would still compile) Would it really hurt VB.net so much to have Control Arrays which it seams to me were quite a simple way of handling things I appreciate there are ways to combine the event handlers and to set and read the "array" of controls in VB.net but WHY should I have to jump through all the extra hoops when I should just be able to use an index value??? It would also help VB6 applications move to VB.net which I would have thought was part of the aim of the .net version developers Gets under desk and puts fingers in ears, ok people fire away!
If you have that many identical controls, maybe you should be adding them through code instead of copy-pasting in the designer. Do that, and you can add them to a collection (Or even build a dictionary or tree if you get bored) at the same time. You could even create the first one of each "array", then do something like this, off the top of my head:
Public Function CreateLotsOfStuff(FirstItem as Control, NumberToCreate as Integer) as List(Of Control)
Dim ctlList as New List(Of Control)
Dim previousItem as Control = FirstItemFor x as Integer = 0 To NumberToCreate - 2 'First one's there already
Dim c as Control = previousItem .Clone()
ctlList.Add(c)
previousItem .Parent.Controls.Add(c)
c.Top = previousItem.Top + previousItem.Height + 5
Next xReturn ctlList
End Function(Haven't done any VB lately, only C#, so my syntax may be a little off)
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)