Textbox array in Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jetean
    New Member
    • Feb 2008
    • 33

    #1

    Textbox array in Class

    Hi:
    I wrote this code:
    Code:
    Class Manager
    private TextBox[] aTextbox = new TextBox[10];
    private string[] sD = new string[10];
    public SerialManager()
            {
                for (int k = 0; k < aTextbox.Length; k++)
                {
                    aTextbox[k] = new TextBox();
                }
    }
             void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
            {
                string msg= comPort.ReadTo("\r");
                TabulatedData(msg);
            }
            public void TabulatedData(string msg)
            {
                for(int j=0;j<7;++j)
                {
                    sD[j] = msg.Substring(7 + j * 4, 4);
                    aTextbox[j].Text = sD[j];
                   
                }
                
            }
    The above code is only partial. I can get the value in sD[ j ], but I'm not able to Display with window Form.
    If I have a Form with Textboxes , How can I Display Values From the Class ?

    Thanks
    Last edited by Jetean; Jul 14 '08, 03:06 PM. Reason: Post Code
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You would need to add the textboxes to your Form.Controls collection.

    Comment

    • Jetean
      New Member
      • Feb 2008
      • 33

      #3
      Originally posted by Plater
      You would need to add the textboxes to your Form.Controls collection.

      How to add ? Can you show me?

      Thanks

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        myForm.Controls .Add(someTextBo x)

        Comment

        • Jetean
          New Member
          • Feb 2008
          • 33

          #5
          Originally posted by Plater
          myForm.Controls .Add(someTextBo x)
          Ah, Ok. But I think may be I question is misunderstood. I have this problem where I created an array of Textboxes in Class file, but I would like to display the textboxes values from Class file onto Form class
          just like this


          Class.Atextbox= Textbox1;

          But how to do it in Array

          Class.Atextbox[]=Textbox [] ???

          Thanks

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Well your class confuses me. You store the values of the textboxes AS well as the textbox(which includes the value).
            Seems a bit bloated/redundant?

            Comment

            • Jetean
              New Member
              • Feb 2008
              • 33

              #7
              Originally posted by Plater
              Well your class confuses me. You store the values of the textboxes AS well as the textbox(which includes the value).
              Seems a bit bloated/redundant?
              Hi Plater:
              I created a class so that I can reused the code again. The class will continously update data and display value in textboxes. So At Form my code will be minimum. I only need to "map" the textboxes from the Form relatively to the Class textboxes during intial Form load.

              by the way what Controls.add can do if all the textboxes are added to control, any example on the usage?

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Hmm, you don;'t normally abstract the GUI out of the GUI, but I guess it could work.
                You could have a function in your class like such:
                [code=c#]
                public void AddControls(Con trolCollection c)
                {
                foreach(TextBox t in aTextbox)
                {
                //some design code for 't' can go here
                c.Add(t);
                }
                }
                [/code]

                Then you could either pass in this.Controls, or like myGroupBox.Cont rols and it will dump the textboxes into there.
                Note: You may have to do some design code too like location/size/etc

                Comment

                • Jetean
                  New Member
                  • Feb 2008
                  • 33

                  #9
                  Originally posted by Plater
                  Hmm, you don;'t normally abstract the GUI out of the GUI, but I guess it could work.
                  You could have a function in your class like such:
                  [code=c#]
                  public void AddControls(Con trolCollection c)
                  {
                  foreach(TextBox t in aTextbox)
                  {
                  //some design code for 't' can go here
                  c.Add(t);
                  }
                  }
                  [/code]

                  Then you could either pass in this.Controls, or like myGroupBox.Cont rols and it will dump the textboxes into there.
                  Note: You may have to do some design code too like location/size/etc
                  Platter:
                  You are saying I add a Function at Form or the Class that I created? ControlCollecti on can only be found in Form but not Class.cs?

                  Then you could either pass in this.Controls, or like myGroupBox.Cont rols and it will dump the textboxes into there.

                  Can you elaborate more?

                  Thanks

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    I said to put it in your class, if you wanted to keep the textboxes in there.
                    But you could do it either way.

                    Comment

                    Working...