How to create control arrays in vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seshu
    New Member
    • Nov 2006
    • 156

    How to create control arrays in vb.net

    Hi Everybody
    Earlier i used to write vb6 code there when ever i copy a textbox and past on same form it used to ask me should i create textbox arrays if i say yes the name used to be like this textbox(0),text box(1) etc but now in vb.net it is not happenning so

    So what i ask is is there any option like that are any controle so that my length of the code decreases and even to study the code it will be eassy
    so someone please help me out

    Regards
    Seshu
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by seshu
    Hi Everybody
    Earlier i used to write vb6 code there when ever i copy a textbox and past on same form it used to ask me should i create textbox arrays if i say yes the name used to be like this textbox(0),text box(1) etc but now in vb.net it is not happenning so

    So what i ask is is there any option like that are any controle so that my length of the code decreases and even to study the code it will be eassy
    so someone please help me out

    Regards
    Seshu
    draw a panel or groupbox....... ...........
    place your controls there....
    you can use .NET control class to write your code
    like that.
    Code:
    For Each ctl As Control In Panel1.Controls
                                   If ctl.Text = "" Then
                        MsgBox("DONT LEFT ANY FIELD BLANK WHILE SAVING",  MsgBoxStyle.Critical, "BLANK FIELDS!!!")
                        Exit Sub
                    End If
                Next

    Comment

    • SammyB
      Recognized Expert Contributor
      • Mar 2007
      • 807

      #3
      Originally posted by seshu
      Hi Everybody
      Earlier i used to write vb6 code there when ever i copy a textbox and past on same form it used to ask me should i create textbox arrays if i say yes the name used to be like this textbox(0),text box(1) etc but now in vb.net it is not happenning so

      So what i ask is is there any option like that are any controle so that my length of the code decreases and even to study the code it will be eassy
      so someone please help me out

      Regards
      Seshu
      It is annoying not to have the VB6 control arrays, but you really don't need them since you can assign an interrupt routine to more than one control: in the properties window, click on the lighting bolt at the top, find the event then use the drop-down to use the same routine as another object. Also, you can make your own arrays/generics of controls. For a rather lengthly example, see http://www.thescripts.com/forum/thread639373.html. Just skip over the first, posts before #9 were using VB6.

      Comment

      • oohay251
        New Member
        • May 2007
        • 27

        #4
        .NET is so much richer for accessing and manipulating controls and their events, control arrays really aren't necessary.
        But if you searched your .NET documents for "control arrays" you'd get a return on the article "Life Without Control Arrays in Visual Basic .NET", http://msdn2.microsoft.com/en-us/lib...42(VS.71).aspx, which may help you.
        It mentioned a compatibility library that actually gives you back control arrays.
        Last edited by SammyB; May 29 '07, 07:43 PM. Reason: added URL.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          If you go to Add Components on your toolbox, you will see various arrays of controls listed (and unchecked) You can ad them there.

          I used to miss that, but I found that after adjusting to not having them, I much prefer without them.

          NOTE: You can always name your controls like mytextbox1 mytextbox2 and then use the .Controls collection that every widget has.
          Code:
          for (int i=0;i<2i++)
          {
             this.Controls["mytextbox"+i.ToString()]
          }

          Comment

          • SammyB
            Recognized Expert Contributor
            • Mar 2007
            • 807

            #6
            Originally posted by Plater
            If you go to Add Components on your toolbox, you will see various arrays of controls listed (and unchecked) You can ad them there.
            This sounds very cool, but I cannot find "Add Components." Ah, never mind, I see it, for VS 2005, it is right-click in Toolbox, Choose Items, but dangerous, notice that they are all in Compatibility.V B6 library.

            Also, from the excellent article that OO referenced, http://msdn2.microsoft.com/en-us/lib...42(VS.71).aspx
            Originally posted by Microsoft
            Note Actually, Visual Basic .NET does support control arrays through the Microsoft Visual Basic .NET Compatibility library. This library allows you to retain some of the Visual Basic 6.0 features in Visual Basic .NET to simplify the migration process. Features of this library should be used only for migration.

            Comment

            • seshu
              New Member
              • Nov 2006
              • 156

              #7
              My goodness i myself dint expect these many replies but any how now i have come to a conclution that if there is somthing there in vb6 and not there in vb.net then it blindly means that here after no need of such things any how thank you everybody once after reading all these links i will come back to you
              Thank you
              Bye

              Comment

              Working...