for each on multiple collections

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

    #1

    for each on multiple collections

    Is there a way to do a "for each" on multiple control collections?
    Something like the following which obviously doesn't work:

    for each ctl as control in form1.controls, form1.tabpage1. controls,
    form2.tabpage2. controls
    next

    Thanks,
    KW


  • Phill W.

    #2
    Re: for each on multiple collections

    Kathy wrote:
    Is there a way to do a "for each" on multiple control collections?
    Something like the following which obviously doesn't work:
    >
    for each ctl as control in form1.controls, form1.tabpage1. controls,
    form2.tabpage2. controls
    next
    Not directly, but you can loop through an /array/ of collections, then
    through the Controls in each, as in :

    <AirCode()_
    For Each e1 As ControlCollecti on _
    In New ControlCollecti on() _
    { Form1.Controls _
    , Form1.tabPage1. Controls _
    , Form2.TabPage2. Controls _
    }
    For Each e2 As Control _
    In e1.Controls
    ' Do stuff
    Next
    Next


    HTH,
    Phill W.

    Comment

    • KW

      #3
      Re: for each on multiple collections

      Yes! That's what I was looking for, thanks !!
      KW

      "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
      news:eg0kel$st5 $1@south.jnrs.j a.net...
      Kathy wrote:
      >Is there a way to do a "for each" on multiple control collections?
      >Something like the following which obviously doesn't work:
      >>
      > for each ctl as control in form1.controls, form1.tabpage1. controls,
      >form2.tabpage2 .controls
      > next
      >
      Not directly, but you can loop through an /array/ of collections, then
      through the Controls in each, as in :
      >
      <AirCode()_
      For Each e1 As ControlCollecti on _
      In New ControlCollecti on() _
      { Form1.Controls _
      , Form1.tabPage1. Controls _
      , Form2.TabPage2. Controls _
      }
      For Each e2 As Control _
      In e1.Controls
      ' Do stuff
      Next
      Next
      >
      >
      HTH,
      Phill W.

      Comment

      • KW

        #4
        Re: for each on multiple collections

        Ooops, I spoke too soon. It sounded good, but I can't get it to work. To
        start with, the ControlCollecti on in "For Each e1 As ControlCollecti on" is
        not recognized. I need a little more help please.
        Thanks.
        KW

        "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
        news:eg0kel$st5 $1@south.jnrs.j a.net...
        Kathy wrote:
        >Is there a way to do a "for each" on multiple control collections?
        >Something like the following which obviously doesn't work:
        >>
        > for each ctl as control in form1.controls, form1.tabpage1. controls,
        >form2.tabpage2 .controls
        > next
        >
        Not directly, but you can loop through an /array/ of collections, then
        through the Controls in each, as in :
        >
        <AirCode()_
        For Each e1 As ControlCollecti on _
        In New ControlCollecti on() _
        { Form1.Controls _
        , Form1.tabPage1. Controls _
        , Form2.TabPage2. Controls _
        }
        For Each e2 As Control _
        In e1.Controls
        ' Do stuff
        Next
        Next
        >
        >
        HTH,
        Phill W.

        Comment

        • Oenone

          #5
          Re: for each on multiple collections

          KW wrote:
          Ooops, I spoke too soon. It sounded good, but I can't get it to
          work. To start with, the ControlCollecti on in "For Each e1 As
          ControlCollecti on" is not recognized. I need a little more help
          please.
          I believe this syntax was only added in VS2005. If you're using VS2003 or
          earlier, try replacing this with:

          \\\
          Dim e1 As ControlCollecti on
          For Each e1 In New ControlCollecti on() {
          [etc]
          ///

          --

          (O)enone


          Comment

          • KW

            #6
            Re: for each on multiple collections

            I'm using VS2005. Intellisense says "type ControlCollecti on is not defined"

            "Oenone" <oenone@nowhere .comwrote in message
            news:dLSUg.622$ L.181@newsfe4-gui.ntli.net...
            KW wrote:
            >Ooops, I spoke too soon. It sounded good, but I can't get it to
            >work. To start with, the ControlCollecti on in "For Each e1 As
            >ControlCollect ion" is not recognized. I need a little more help
            >please.
            >
            I believe this syntax was only added in VS2005. If you're using VS2003 or
            earlier, try replacing this with:
            >
            \\\
            Dim e1 As ControlCollecti on
            For Each e1 In New ControlCollecti on() {
            [etc]
            ///
            >
            --
            >
            (O)enone
            >

            Comment

            • Oenone

              #7
              Re: for each on multiple collections

              KW wrote:
              I'm using VS2005. Intellisense says "type ControlCollecti on is not
              defined"
              In that case try putting the class hierarchy above ControlCollecti on, and
              use Windows.Forms.C ontrol.ControlC ollection instead.

              --

              (O)enone


              Comment

              • Dennis

                #8
                RE: for each on multiple collections

                To be sure you get all the child controls from other child controls, you will
                need some type of recursion. Try the following (untested)

                'Public Sub Get_Controls(By Val parentCtr As Control)
                ' For Each ctr As Control In parentCtr.Contr ols
                ' Console.Write(c tr.Name)
                ' Get_Controls(ct r)
                ' Next
                'End Sub
                --
                Dennis in Houston


                "Kathy" wrote:
                Is there a way to do a "for each" on multiple control collections?
                Something like the following which obviously doesn't work:
                >
                for each ctl as control in form1.controls, form1.tabpage1. controls,
                form2.tabpage2. controls
                next
                >
                Thanks,
                KW
                >
                >
                >

                Comment

                Working...