sum the values from dynamically formed textboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashwinigopi
    New Member
    • Jul 2008
    • 7

    sum the values from dynamically formed textboxes

    Hi

    I managed to dynamically form textboxes using c#. I want include another button, whenever i enter any values in those textboxes i should get sum in message box. i donno how to use code for dynamic texboxes. This is what i have done,
    [code=c#]
    namespace WindowsFormsApp lication1
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeCompo nent();
    }

    private void button1_Click(o bject sender, EventArgs e)
    {
    int y=50;
    int j = int.Parse(textB ox1.Text);
    TextBox[] txt = new TextBox[j];
    if (j < 20)
    {
    for (int i = 0; i < j; i++)
    {
    txt[i] = new TextBox();
    txt[i].AutoSize = true;

    txt[i].Location = new Point(150, y);

    this.Controls.A dd(txt[i]);
    y = y + 30;

    }
    }
    else
    {
    MessageBox.Show (" enter values below 20");
    }
    }

    private void button2_Click(o bject sender, EventArgs e)
    {

    }

    private void Form1_Load(obje ct sender, EventArgs e)
    {

    }

    }
    }
    [/code]
    What code should i use to add the values in the textbox
    Last edited by Plater; Aug 7 '08, 02:43 PM. Reason: cod4e tags, cleaned up wasted space
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Seems pretty basic?
    Get value from textbox.
    Convert to a number
    Add number.

    ???

    Comment

    • ashwinigopi
      New Member
      • Jul 2008
      • 7

      #3
      Originally posted by Plater
      Seems pretty basic?
      Get value from textbox.
      Convert to a number
      Add number.

      ???
      I am just a learner, i donno how to get the value from the textbox?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Originally posted by ashwinigopi
        I am just a learner, i donno how to get the value from the textbox?

        Comment

        Working...