control array question for VB.Net 2005

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

    control array question for VB.Net 2005

    Hello,

    I have an application that contains several checkboxes. I originally
    created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I
    understand the vb2005 supports control arrays. Is this correct? If so, I
    would like to convert my checkboxes to a control array, but without having to
    recreate them from scratch because their placement was a real pain. Is it
    possible to go to the property sheet of each checkbox and assign it a
    position in the control array? like checkbox0 would be chk(0), and checkbox1
    would be chk(1). Am I doing this correctly?

    Thanks,
    Rich
  • Chris

    #2
    Re: control array question for VB.Net 2005

    Rich wrote:[color=blue]
    > Hello,
    >
    > I have an application that contains several checkboxes. I originally
    > created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I
    > understand the vb2005 supports control arrays. Is this correct? If so, I
    > would like to convert my checkboxes to a control array, but without having to
    > recreate them from scratch because their placement was a real pain. Is it
    > possible to go to the property sheet of each checkbox and assign it a
    > position in the control array? like checkbox0 would be chk(0), and checkbox1
    > would be chk(1). Am I doing this correctly?
    >
    > Thanks,
    > Rich[/color]

    I'm a bit confused on what you are trying to do. You could always go:

    Dim Arr(10) as Array
    Arr(0) = CheckBox1

    That being said you could do this at the begining of your form load and
    then have your control array without changing the declaration of the
    controls.

    Chris

    Comment

    • Rich

      #3
      Re: control array question for VB.Net 2005

      Thanks for your reply. Actually, I did do the array thing. Then I tried to
      overload the OnEnter event of the controls (actually for textboxes, which is
      where I was going to go next with the control array thing). Here is what I
      have so far:

      Dim arrCtrl As Control()

      Private Sub From1_Load(...)
      arrCtrl = New TextBox(){txt1, txt2, txt3}
      ....
      End Sub

      Private Overloads Sub OnEnter(ByVal sender As System.Object, _
      ByVal e As System.EventArg s) Handles
      arrCtlr().enter
      MessageBox.Show ("Textbox " & CType(sender, TextBox).Name)
      End Sub

      I have a problem with ...Handles arrCtlr().Enter
      I have tried ...Handles arrCtlr.Enter but I get an error message that says
      something about needing to use WithEvents. What is the correct syntax for
      passing an array of controls to an overloaded Event procedure?

      Thanks,
      Rich


      "Chris" wrote:
      [color=blue]
      > Rich wrote:[color=green]
      > > Hello,
      > >
      > > I have an application that contains several checkboxes. I originally
      > > created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I
      > > understand the vb2005 supports control arrays. Is this correct? If so, I
      > > would like to convert my checkboxes to a control array, but without having to
      > > recreate them from scratch because their placement was a real pain. Is it
      > > possible to go to the property sheet of each checkbox and assign it a
      > > position in the control array? like checkbox0 would be chk(0), and checkbox1
      > > would be chk(1). Am I doing this correctly?
      > >
      > > Thanks,
      > > Rich[/color]
      >
      > I'm a bit confused on what you are trying to do. You could always go:
      >
      > Dim Arr(10) as Array
      > Arr(0) = CheckBox1
      >
      > That being said you could do this at the begining of your form load and
      > then have your control array without changing the declaration of the
      > controls.
      >
      > Chris
      >[/color]

      Comment

      • ronchese

        #4
        Re: control array question for VB.Net 2005

        Write a method to centralize your calls:
        Private Sub HandleEnter(ByV al sender As Object, ByVal e As System.EventArg s)
        '...
        End Sub

        Then, for each control in your array, use the AddHandler statement, pointing the Enter event of textbox to that procedure:
        AddHandler Textbox.Enter, AddressOf HandleEnter

        When you close the form, call the RemoveHandler statement.

        That's all.

        []s
        Cesar









        "Rich" <Rich@discussio ns.microsoft.co m> wrote in message news:8D689E91-CF44-4BB2-9307-5E3D4BDE0023@mi crosoft.com...[color=blue]
        > Thanks for your reply. Actually, I did do the array thing. Then I tried to
        > overload the OnEnter event of the controls (actually for textboxes, which is
        > where I was going to go next with the control array thing). Here is what I
        > have so far:
        >
        > Dim arrCtrl As Control()
        >
        > Private Sub From1_Load(...)
        > arrCtrl = New TextBox(){txt1, txt2, txt3}
        > ...
        > End Sub
        >
        > Private Overloads Sub OnEnter(ByVal sender As System.Object, _
        > ByVal e As System.EventArg s) Handles
        > arrCtlr().enter
        > MessageBox.Show ("Textbox " & CType(sender, TextBox).Name)
        > End Sub
        >
        > I have a problem with ...Handles arrCtlr().Enter
        > I have tried ...Handles arrCtlr.Enter but I get an error message that says
        > something about needing to use WithEvents. What is the correct syntax for
        > passing an array of controls to an overloaded Event procedure?
        >
        > Thanks,
        > Rich
        >
        >
        > "Chris" wrote:
        > [color=green]
        >> Rich wrote:[color=darkred]
        >> > Hello,
        >> >
        >> > I have an application that contains several checkboxes. I originally
        >> > created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I
        >> > understand the vb2005 supports control arrays. Is this correct? If so, I
        >> > would like to convert my checkboxes to a control array, but without having to
        >> > recreate them from scratch because their placement was a real pain. Is it
        >> > possible to go to the property sheet of each checkbox and assign it a
        >> > position in the control array? like checkbox0 would be chk(0), and checkbox1
        >> > would be chk(1). Am I doing this correctly?
        >> >
        >> > Thanks,
        >> > Rich[/color]
        >>
        >> I'm a bit confused on what you are trying to do. You could always go:
        >>
        >> Dim Arr(10) as Array
        >> Arr(0) = CheckBox1
        >>
        >> That being said you could do this at the begining of your form load and
        >> then have your control array without changing the declaration of the
        >> controls.
        >>
        >> Chris
        >>[/color][/color]

        Comment

        • Rich

          #5
          Re: control array question for VB.Net 2005

          Thanks. I sort of get it. How do I invoke/call AddHandler? I enter a
          textbox with the mouse. How does AddHandler get called? My goal is to avoid
          writing the same routine 20 times for 20 textboxes.

          Private Sub txt1_OnEnter(.. .) Handles...

          How do I write the Addhandler so I only have one routine for all of my
          textboxes? Thinking outloud here, do I add the AddHandler call in the array?

          arrCtl = new Control(){txt1, txt2, txt3}

          I don't know how to add the AddHandler call.


          "ronchese" wrote:
          [color=blue]
          > Write a method to centralize your calls:
          > Private Sub HandleEnter(ByV al sender As Object, ByVal e As System.EventArg s)
          > '...
          > End Sub
          >
          > Then, for each control in your array, use the AddHandler statement, pointing the Enter event of textbox to that procedure:
          > AddHandler Textbox.Enter, AddressOf HandleEnter
          >
          > When you close the form, call the RemoveHandler statement.
          >
          > That's all.
          >
          > []s
          > Cesar
          >
          >
          >
          >
          >
          >
          >
          >
          >
          > "Rich" <Rich@discussio ns.microsoft.co m> wrote in message news:8D689E91-CF44-4BB2-9307-5E3D4BDE0023@mi crosoft.com...[color=green]
          > > Thanks for your reply. Actually, I did do the array thing. Then I tried to
          > > overload the OnEnter event of the controls (actually for textboxes, which is
          > > where I was going to go next with the control array thing). Here is what I
          > > have so far:
          > >
          > > Dim arrCtrl As Control()
          > >
          > > Private Sub From1_Load(...)
          > > arrCtrl = New TextBox(){txt1, txt2, txt3}
          > > ...
          > > End Sub
          > >
          > > Private Overloads Sub OnEnter(ByVal sender As System.Object, _
          > > ByVal e As System.EventArg s) Handles
          > > arrCtlr().enter
          > > MessageBox.Show ("Textbox " & CType(sender, TextBox).Name)
          > > End Sub
          > >
          > > I have a problem with ...Handles arrCtlr().Enter
          > > I have tried ...Handles arrCtlr.Enter but I get an error message that says
          > > something about needing to use WithEvents. What is the correct syntax for
          > > passing an array of controls to an overloaded Event procedure?
          > >
          > > Thanks,
          > > Rich
          > >
          > >
          > > "Chris" wrote:
          > >[color=darkred]
          > >> Rich wrote:
          > >> > Hello,
          > >> >
          > >> > I have an application that contains several checkboxes. I originally
          > >> > created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I
          > >> > understand the vb2005 supports control arrays. Is this correct? If so, I
          > >> > would like to convert my checkboxes to a control array, but without having to
          > >> > recreate them from scratch because their placement was a real pain. Is it
          > >> > possible to go to the property sheet of each checkbox and assign it a
          > >> > position in the control array? like checkbox0 would be chk(0), and checkbox1
          > >> > would be chk(1). Am I doing this correctly?
          > >> >
          > >> > Thanks,
          > >> > Rich
          > >>
          > >> I'm a bit confused on what you are trying to do. You could always go:
          > >>
          > >> Dim Arr(10) as Array
          > >> Arr(0) = CheckBox1
          > >>
          > >> That being said you could do this at the begining of your form load and
          > >> then have your control array without changing the declaration of the
          > >> controls.
          > >>
          > >> Chris
          > >>[/color][/color][/color]

          Comment

          • Rich

            #6
            Re: control array question for VB.Net 2005

            I figured it out.

            Dim ctl as control()
            Private Sub Form_Load(...)
            ctl = new ctl(){txt1, txt2, txt3}
            Dim txt As TextBox
            For Each txt In ctl
            AddHandler txt.Enter, AddressOf HandleEnter
            next

            Private Sub HandleEnter(... )
            MessageBox.Show (Ctype(sender, TextBox).Name)
            End Sub

            "Rich" wrote:
            [color=blue]
            > Thanks. I sort of get it. How do I invoke/call AddHandler? I enter a
            > textbox with the mouse. How does AddHandler get called? My goal is to avoid
            > writing the same routine 20 times for 20 textboxes.
            >
            > Private Sub txt1_OnEnter(.. .) Handles...
            >
            > How do I write the Addhandler so I only have one routine for all of my
            > textboxes? Thinking outloud here, do I add the AddHandler call in the array?
            >
            > arrCtl = new Control(){txt1, txt2, txt3}
            >
            > I don't know how to add the AddHandler call.
            >
            >
            > "ronchese" wrote:
            >[color=green]
            > > Write a method to centralize your calls:
            > > Private Sub HandleEnter(ByV al sender As Object, ByVal e As System.EventArg s)
            > > '...
            > > End Sub
            > >
            > > Then, for each control in your array, use the AddHandler statement, pointing the Enter event of textbox to that procedure:
            > > AddHandler Textbox.Enter, AddressOf HandleEnter
            > >
            > > When you close the form, call the RemoveHandler statement.
            > >
            > > That's all.
            > >
            > > []s
            > > Cesar
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            > > "Rich" <Rich@discussio ns.microsoft.co m> wrote in message news:8D689E91-CF44-4BB2-9307-5E3D4BDE0023@mi crosoft.com...[color=darkred]
            > > > Thanks for your reply. Actually, I did do the array thing. Then I tried to
            > > > overload the OnEnter event of the controls (actually for textboxes, which is
            > > > where I was going to go next with the control array thing). Here is what I
            > > > have so far:
            > > >
            > > > Dim arrCtrl As Control()
            > > >
            > > > Private Sub From1_Load(...)
            > > > arrCtrl = New TextBox(){txt1, txt2, txt3}
            > > > ...
            > > > End Sub
            > > >
            > > > Private Overloads Sub OnEnter(ByVal sender As System.Object, _
            > > > ByVal e As System.EventArg s) Handles
            > > > arrCtlr().enter
            > > > MessageBox.Show ("Textbox " & CType(sender, TextBox).Name)
            > > > End Sub
            > > >
            > > > I have a problem with ...Handles arrCtlr().Enter
            > > > I have tried ...Handles arrCtlr.Enter but I get an error message that says
            > > > something about needing to use WithEvents. What is the correct syntax for
            > > > passing an array of controls to an overloaded Event procedure?
            > > >
            > > > Thanks,
            > > > Rich
            > > >
            > > >
            > > > "Chris" wrote:
            > > >
            > > >> Rich wrote:
            > > >> > Hello,
            > > >> >
            > > >> > I have an application that contains several checkboxes. I originally
            > > >> > created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I
            > > >> > understand the vb2005 supports control arrays. Is this correct? If so, I
            > > >> > would like to convert my checkboxes to a control array, but without having to
            > > >> > recreate them from scratch because their placement was a real pain. Is it
            > > >> > possible to go to the property sheet of each checkbox and assign it a
            > > >> > position in the control array? like checkbox0 would be chk(0), and checkbox1
            > > >> > would be chk(1). Am I doing this correctly?
            > > >> >
            > > >> > Thanks,
            > > >> > Rich
            > > >>
            > > >> I'm a bit confused on what you are trying to do. You could always go:
            > > >>
            > > >> Dim Arr(10) as Array
            > > >> Arr(0) = CheckBox1
            > > >>
            > > >> That being said you could do this at the begining of your form load and
            > > >> then have your control array without changing the declaration of the
            > > >> controls.
            > > >>
            > > >> Chris
            > > >>[/color][/color][/color]

            Comment

            • ronchese

              #7
              Re: control array question for VB.Net 2005

              Yeah!

              :^D


              "Rich" <Rich@discussio ns.microsoft.co m> wrote in message
              news:38326B75-B288-417A-BA01-345306B2FAAD@mi crosoft.com...[color=blue]
              >I figured it out.
              >
              > Dim ctl as control()
              > Private Sub Form_Load(...)
              > ctl = new ctl(){txt1, txt2, txt3}
              > Dim txt As TextBox
              > For Each txt In ctl
              > AddHandler txt.Enter, AddressOf HandleEnter
              > next
              >
              > Private Sub HandleEnter(... )
              > MessageBox.Show (Ctype(sender, TextBox).Name)
              > End Sub
              >
              > "Rich" wrote:
              >[color=green]
              >> Thanks. I sort of get it. How do I invoke/call AddHandler? I enter a
              >> textbox with the mouse. How does AddHandler get called? My goal is to
              >> avoid
              >> writing the same routine 20 times for 20 textboxes.
              >>
              >> Private Sub txt1_OnEnter(.. .) Handles...
              >>
              >> How do I write the Addhandler so I only have one routine for all of my
              >> textboxes? Thinking outloud here, do I add the AddHandler call in the
              >> array?
              >>
              >> arrCtl = new Control(){txt1, txt2, txt3}
              >>
              >> I don't know how to add the AddHandler call.
              >>
              >>
              >> "ronchese" wrote:
              >>[color=darkred]
              >> > Write a method to centralize your calls:
              >> > Private Sub HandleEnter(ByV al sender As Object, ByVal e As
              >> > System.EventArg s)
              >> > '...
              >> > End Sub
              >> >
              >> > Then, for each control in your array, use the AddHandler statement,
              >> > pointing the Enter event of textbox to that procedure:
              >> > AddHandler Textbox.Enter, AddressOf HandleEnter
              >> >
              >> > When you close the form, call the RemoveHandler statement.
              >> >
              >> > That's all.
              >> >
              >> > []s
              >> > Cesar
              >> >
              >> >
              >> >
              >> >
              >> >
              >> >
              >> >
              >> >
              >> >
              >> > "Rich" <Rich@discussio ns.microsoft.co m> wrote in message
              >> > news:8D689E91-CF44-4BB2-9307-5E3D4BDE0023@mi crosoft.com...
              >> > > Thanks for your reply. Actually, I did do the array thing. Then I
              >> > > tried to
              >> > > overload the OnEnter event of the controls (actually for textboxes,
              >> > > which is
              >> > > where I was going to go next with the control array thing). Here is
              >> > > what I
              >> > > have so far:
              >> > >
              >> > > Dim arrCtrl As Control()
              >> > >
              >> > > Private Sub From1_Load(...)
              >> > > arrCtrl = New TextBox(){txt1, txt2, txt3}
              >> > > ...
              >> > > End Sub
              >> > >
              >> > > Private Overloads Sub OnEnter(ByVal sender As System.Object, _
              >> > > ByVal e As System.EventArg s)
              >> > > Handles
              >> > > arrCtlr().enter
              >> > > MessageBox.Show ("Textbox " & CType(sender, TextBox).Name)
              >> > > End Sub
              >> > >
              >> > > I have a problem with ...Handles arrCtlr().Enter
              >> > > I have tried ...Handles arrCtlr.Enter but I get an error message that
              >> > > says
              >> > > something about needing to use WithEvents. What is the correct
              >> > > syntax for
              >> > > passing an array of controls to an overloaded Event procedure?
              >> > >
              >> > > Thanks,
              >> > > Rich
              >> > >
              >> > >
              >> > > "Chris" wrote:
              >> > >
              >> > >> Rich wrote:
              >> > >> > Hello,
              >> > >> >
              >> > >> > I have an application that contains several checkboxes. I
              >> > >> > originally
              >> > >> > created this app in VB.Net 2003 and upgraded the app to VB.Net
              >> > >> > 2005. I
              >> > >> > understand the vb2005 supports control arrays. Is this correct?
              >> > >> > If so, I
              >> > >> > would like to convert my checkboxes to a control array, but
              >> > >> > without having to
              >> > >> > recreate them from scratch because their placement was a real
              >> > >> > pain. Is it
              >> > >> > possible to go to the property sheet of each checkbox and assign
              >> > >> > it a
              >> > >> > position in the control array? like checkbox0 would be chk(0),
              >> > >> > and checkbox1
              >> > >> > would be chk(1). Am I doing this correctly?
              >> > >> >
              >> > >> > Thanks,
              >> > >> > Rich
              >> > >>
              >> > >> I'm a bit confused on what you are trying to do. You could always
              >> > >> go:
              >> > >>
              >> > >> Dim Arr(10) as Array
              >> > >> Arr(0) = CheckBox1
              >> > >>
              >> > >> That being said you could do this at the begining of your form load
              >> > >> and
              >> > >> then have your control array without changing the declaration of the
              >> > >> controls.
              >> > >>
              >> > >> Chris
              >> > >>[/color][/color][/color]


              Comment

              Working...