accessing control collection in tabcontrol

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sudhakara.T.P.

    #1

    accessing control collection in tabcontrol

    Hi,
    I have an tab control in one of the forms and it has two tab strips. Now I
    have written an general function that accepts form name as parameter and
    iterates through all the controls in the form and re-initialises that.
    Now in this context, i have around 15 controls on one of the tab strips page
    1 and 5 controls in tab strip 2.
    now when i iterate through the controls, i am getting the control collection
    as 3 as there are two more button on the page.
    Can anyone please help me how do i access all the controls on the tabstrip.
    Here is the code that i am using for the same.

    Public Sub ClearFormElemen ts(ByVal sForm As Form)
    Dim vControl As System.Windows. Forms.Control

    For Each vControl In sForm.Controls
    If TypeOf vControl Is System.Windows. Forms.TextBox Then
    vControl.Text = ""
    End If

    If TypeOf vControl Is System.Windows. Forms.ComboBox Then
    vControl.Text = ""
    End If

    If TypeOf vControl Is System.Windows. Forms.DateTimeP icker Then
    vControl.Text = Convert.ToDateT ime(Now()).ToSt ring
    End If

    If TypeOf vControl Is
    System.Windows. Forms.TabContro l.ControlCollec tion Then

    End If
    Next
    End Sub

    Regards
    Sudhakara.T.P.
  • Cor Ligthert [MVP]

    #2
    Re: accessing control collection in tabcontrol

    Sudhakara,

    I did not completly try this routine, however I think that it fullfils your
    needs.

    \\\
    doset(MyTabCont rol)
    ///
    \\\
    Private Sub doSet(ByVal parentCtr As Control)
    Dim ctr As Control
    For Each ctr In parentCtr.Contr ols
    ctr.Text = Nothing
    doSet(ctr)
    Next
    ///
    This should set every control in your tabcontrol to its initial state.
    (Assuming that you did not set something using the designer)

    Every control inherits from control from which text is a property.

    I hope this helps,

    Cor

    End Sub


    Comment

    • Sudhakara.T.P.

      #3
      Re: accessing control collection in tabcontrol

      Hi Cor Lighert,

      Bravo !!!! That worked like a Bullseye. Thanks for the information.

      Thanks & Regards
      Sudhakara.T.P.

      "Cor Ligthert [MVP]" wrote:
      [color=blue]
      > Sudhakara,
      >
      > I did not completly try this routine, however I think that it fullfils your
      > needs.
      >
      > \\\
      > doset(MyTabCont rol)
      > ///
      > \\\
      > Private Sub doSet(ByVal parentCtr As Control)
      > Dim ctr As Control
      > For Each ctr In parentCtr.Contr ols
      > ctr.Text = Nothing
      > doSet(ctr)
      > Next
      > ///
      > This should set every control in your tabcontrol to its initial state.
      > (Assuming that you did not set something using the designer)
      >
      > Every control inherits from control from which text is a property.
      >
      > I hope this helps,
      >
      > Cor
      >
      > End Sub
      >
      >
      >[/color]

      Comment

      • Sudhakara.T.P.

        #4
        Re: accessing control collection in tabcontrol

        Hi,
        In continuation with our discussion, with this generic function, as we clear
        the text box like vControl.text=" ", how can we uncheck a check box. Because
        when I say this vControl.checke d=false, it gives an error. Any idea about
        this. If possible, can you let me know where I can find these type of
        information.

        Regards
        Sudhakara.T.P.[color=blue]
        > "Cor Ligthert [MVP]" wrote:
        >[color=green]
        > > Sudhakara,
        > >
        > > I did not completly try this routine, however I think that it fullfils your
        > > needs.
        > >
        > > \\\
        > > doset(MyTabCont rol)
        > > ///
        > > \\\
        > > Private Sub doSet(ByVal parentCtr As Control)
        > > Dim ctr As Control
        > > For Each ctr In parentCtr.Contr ols
        > > ctr.Text = Nothing
        > > doSet(ctr)
        > > Next
        > > ///
        > > This should set every control in your tabcontrol to its initial state.
        > > (Assuming that you did not set something using the designer)
        > >
        > > Every control inherits from control from which text is a property.
        > >
        > > I hope this helps,
        > >
        > > Cor
        > >
        > > End Sub
        > >
        > >
        > >[/color][/color]

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: accessing control collection in tabcontrol

          Sukhakara,

          In this case does the text set the text from that box. The checkstate is

          if typeof ctr Is checkbox then
          ctr.CheckState = CheckState.Unch ecked
          End if

          I hope this helps,

          Cor



          Comment

          • Sudhakara.T.P.

            #6
            Re: accessing control collection in tabcontrol

            Hi Cor,
            As I have declared ctr as system.windows. forms.control, the moment I type
            ctr.checkState, it gives an compile error saying that checkstate is not a
            member of system.windows. forms.control. Any updates on this.

            I had tried this earlier, but had the same problem.

            Regards
            Sudhakara.T.P.

            "Cor Ligthert [MVP]" wrote:
            [color=blue]
            > Sukhakara,
            >
            > In this case does the text set the text from that box. The checkstate is
            >
            > if typeof ctr Is checkbox then
            > ctr.CheckState = CheckState.Unch ecked
            > End if
            >
            > I hope this helps,
            >
            > Cor
            >
            >
            >
            >[/color]

            Comment

            • Cor Ligthert [MVP]

              #7
              Re: accessing control collection in tabcontrol

              Sukhakara,

              Sometimes I type things direct in the message and see than that I do crazy
              things, I do it now again however assume it is now right.

              Text is a property from Control, however checkstate not that is added with
              the created checkbox which inherits from control. And therefore should be
              told that it is a checkbox

              \\\
              if typeof ctr Is checkbox then
              directcast(ctr, checkbox).Check State = CheckState.Unch ecked
              End if
              ///

              I hope that this goes better.

              Cor


              Comment

              • Sudhakara.T.P.

                #8
                Re: accessing control collection in tabcontrol

                Hi Cor,

                Thanks. That worked the way it should have.

                Thanks once again and that is the reason why I always rely on this site.

                Thanks
                Sudhakara.T.P.

                "Cor Ligthert [MVP]" wrote:
                [color=blue]
                > Sukhakara,
                >
                > Sometimes I type things direct in the message and see than that I do crazy
                > things, I do it now again however assume it is now right.
                >
                > Text is a property from Control, however checkstate not that is added with
                > the created checkbox which inherits from control. And therefore should be
                > told that it is a checkbox
                >
                > \\\
                > if typeof ctr Is checkbox then
                > directcast(ctr, checkbox).Check State = CheckState.Unch ecked
                > End if
                > ///
                >
                > I hope that this goes better.
                >
                > Cor
                >
                >
                >[/color]

                Comment

                Working...