Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Why are there no form control arrays in vb.net?

Why are there no form control arrays in vb.net?

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasedata-structureshelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MikeD 2
    wrote on last edited by
    #1

    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!

    D L I 3 Replies Last reply
    0
    • M MikeD 2

      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!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • M MikeD 2

        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!

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        0
        • L Luc Pattyn

          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.

          M Offline
          M Offline
          MikeD 2
          wrote on last edited by
          #4

          Luc Pattyn wrote:

          you can always use myContainer.Controls(index)

          true if they are the only controls in that container otherwise it wastes resources putting invisible frames under groups of controls

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            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

            M Offline
            M Offline
            MikeD 2
            wrote on last edited by
            #5

            Dave 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?

            1 Reply Last reply
            0
            • M MikeD 2

              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 Offline
              I Offline
              Ian Shlasko
              wrote on last edited by
              #6

              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 = FirstItem

              For 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 x

              Return 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)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups