An array of controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sheldon

    An array of controls

    In versions of VB prior to .net, I was able to create in code an array of
    controls, such as

    for i = 1 to 10
    Load Me.lblTest(i)
    Me.lblTest(i).t op = me.lblTest(i-1).top - me.lblTest(i-1).height - 200
    Me.lblTest(i).v isible = true
    next i

    where lblTest(0) already exists on the form.

    How do I do this in VB.net

    Thanks
  • Herfried K. Wagner [MVP]

    #2
    Re: An array of controls

    "Sheldon" <Sheldon@discus sions.microsoft .com> schrieb:[color=blue]
    > In versions of VB prior to .net, I was able to create in code an array of
    > controls[/color]

    Accessing controls by their names or indices
    <URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbyna meindex&lang=en >

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • Peter van der Goes

      #3
      Re: An array of controls


      "Sheldon" <Sheldon@discus sions.microsoft .com> wrote in message
      news:AFCDA814-9780-4D08-B249-7C0121A5394F@mi crosoft.com...[color=blue]
      > In versions of VB prior to .net, I was able to create in code an array of
      > controls, such as
      >
      > for i = 1 to 10
      > Load Me.lblTest(i)
      > Me.lblTest(i).t op = me.lblTest(i-1).top - me.lblTest(i-1).height -
      > 200
      > Me.lblTest(i).v isible = true
      > next i
      >
      > where lblTest(0) already exists on the form.
      >
      > How do I do this in VB.net
      >
      > Thanks[/color]

      Read up on the .NET Framework Form.ControlCol lection class in the help. You
      also may find another article helpful: search in the help for "Controls
      Collection Changes in Visual Basic .NET".

      --
      Peter [MVP Visual Developer]
      Jack of all trades, master of none.


      Comment

      • Andy O'Neill

        #4
        Re: An array of controls

        "Sheldon" <Sheldon@discus sions.microsoft .com> wrote in message
        news:AFCDA814-9780-4D08-B249-7C0121A5394F@mi crosoft.com...[color=blue]
        > In versions of VB prior to .net, I was able to create in code an array of
        > controls, such as
        >
        > for i = 1 to 10
        > Load Me.lblTest(i)
        > Me.lblTest(i).t op = me.lblTest(i-1).top - me.lblTest(i-1).height -
        > 200
        > Me.lblTest(i).v isible = true
        > next i
        >
        > where lblTest(0) already exists on the form.
        >
        > How do I do this in VB.net
        >
        > Thanks[/color]

        You need to get used to the object thing in .net.
        It's a different way of looking at things.
        So..

        You can inherit one control from another.
        So you could create a new control based on like a "master" label0.
        That way it inherits all the event code you have.

        Depends on the reason you want to do this though.

        Say you want to run access reports from vb.
        So you have some code works out what you got in a given mdb dynamically and
        your use of control array functionality was so you had a label and button
        per report.
        You want a list of reports, descriptions and buttons and all built
        dynamically.
        Click on a button and your code runs the report it's next to.
        You could do this using a datagrid based on an array.
        Arrays contain objects now.
        So you can have a class exposes 3 properties, rep_description , rep_name,
        rep_access_name .
        Link a datagrid to an array of these.
        You need to look into getting a button into a grid and turn off append but
        that's all on george shepherd's faq page ( google, it now if you ain't read
        his stuff).
        Otherwise the code's kind of easier.
        Well, less messy.
        No mucking about getting button two under button3.
        You can't hit the end of a page.
        Well, maybe not the first time you write it, seeing as how it's different.
        But the second time'll be easy.

        If you were doing asp.net I reckon probably even simpler because you'd have
        a more suitable control available.
        Seems to me they invested more effort in the asp functionality.
        Mind you, it needed fixing more.

        --
        Regards,
        Andy O'Neill


        Comment

        Working...