We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

create texbox(dynamics) and pass the i valor

(sorry for my english...)
I have created a textbox where i take the number of textboxes that i must create...
i created the textboxes pressing a button whit this...

N = Convert.ToInt32(textBox1.Text); //N is a global variable...
                ValoriText = new TextBox[N];
                for (int i = 2; i <= N + 1; i++)
                {
                    string textname = "textBox_f" + i;
                    TextBox txtTemp = new TextBox();
                    txtTemp.Location = new System.Drawing.Point(50, 200 + 26 * i);
                    txtTemp.Size = new System.Drawing.Size(200, 25);
                    txtTemp.Name = textname;
                    txtTemp.Width = 100;
                    this.Controls.Add(txtTemp);
                }

well...after this i'd like to press another button and control that is write in the textboxxes(because i want only number) , and if these numbers are corrects, press another button and do the rest...

the problem is that i don't understand how i may do the second button because the valors are not passed from the first button where the textboxes was created...sorry again for my inglish...

3
Contributors
9
Replies
5 Days
Discussion Span
6 Months Ago
Last Updated
10
Views
stefano.a.feltre
Newbie Poster
7 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

First of all never heard of "ValoriText", also do you mind posting more of your code?

I am having a little trouble understanding what you are asking but if I see more of your code I might be able to figure it out

Ange1ofD4rkness
Posting Whiz in Training
211 posts since May 2010
Reputation Points: 10
Solved Threads: 7
Skill Endorsements: 2

yes sure...
I don't know because "TextBox" is chanched in "ValoriText"...

long N;
        public Multinomiale()
        {
            InitializeComponent();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form_capitolo_1 f = new Form_capitolo_1();
            f.Show();
            this.Visible = false;
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            bool Tn = Controllo_TextBox(textBox1.Text);
            if (Tn == false)
            {
                MessageBox.Show("'n' deve essere un numero intero maggiore di 0!");
                textBox1.Text = "";
            }
            else if (Tn == true)
            {
                N = Convert.ToInt32(textBox1.Text);
                for (int i = 2; i <= N+1; i++)
                {
                    string textname = "textBox_f" + i;
                    TextBox txtTemp = new TextBox();
                    txtTemp.Location = new System.Drawing.Point(50, 200 + 26 * i);
                    txtTemp.Size = new System.Drawing.Size(200, 25);
                    txtTemp.Name = textname;
                    txtTemp.Width = 100;
                    this.Controls.Add(txtTemp);
                }
            }
        }

 private void button2_Click(object sender, EventArgs e)
        {
            //now in this botton i'd like to receve the "numbers" of what is written in the textboxes(dynamics)
            //and pass it in a method for a control of what is written in it...

        }
stefano.a.feltre
Newbie Poster
7 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Draw a Panel and a Text box and set its property multiline = true in your Form and modify the line no "32" to

this.panel1.Controls.Add(txtTemp);      

Now write loop code in button2_click

private void button2_Click(object sender, EventArgs e)
        {

            foreach (Control cont in panel1.Controls )
            {
                if (cont is TextBox)
                {
                    //txtresult is your textbox for result of all textbox
                    txtresult.AppendText(((TextBox)cont).Text);
                }                    
                }
        }

Hope this help you.

yousafc#
Junior Poster in Training
98 posts since Feb 2011
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0

Sorry,but i don't understand... what should i modify to txtresult?What is it? it's result of ALL texbox? i don't understand sorry, I'm of first weaponry :(

stefano.a.feltre
Newbie Poster
7 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I modify "txtResult" in the name of the new textbox, but what is the functionary of this textbox? And when i clck button1 the texboxes was created under the panel...

stefano.a.feltre
Newbie Poster
7 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Ok i unterstand the functionary of txtResult but...I have to take the number of each of the textbox,because in ceirt there will be ',' in other not...

stefano.a.feltre
Newbie Poster
7 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Now I Not UnderStand You.What Do You Want?
Do You Want Show All TextBoxes Number How Many User Created Dynamically Or What user Write in said TextBox.Tell us Clearly.

yousafc#
Junior Poster in Training
98 posts since Feb 2011
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0

Sorry if i wasn't clear...After i've created the textboxes, i write a number in each of them(with "," or without it)...I have to received each of that number separatly, not the sum in other textbox...

stefano.a.feltre
Newbie Poster
7 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Stefano, the code yousafc# gave you, the foreach loop, let me break it down

private void button2_Click(object sender, EventArgs e)
{      
    foreach (Control cont in panel1.Controls) //goes through all the items in panel1
    {
        if (cont is TextBox) //if the item is a TextBox
        {
            txtresult.AppendText(((TextBox)cont).Text); 
            //take the text from the current textBox, and add it onto the txtresult text box
        }                    
    }
}

In other words what he's doing is taking all that text from all those Text Boxes and joining it all together in one text box which is called txtresult.

(to make it easier let me use your code and put the new name in "TextBox txtresult = new TextBox();", that make sense? I'm not saying use that line I posted, I am showing you what this item is you are using).

If you want to add a comma do this, instead of,

txtresult.AppendText(((TextBox)cont).Text); 

Write it like this,

txtresult.AppendText(((TextBox)cont).Text + ", "); 

That will put a comma and a space after every number

So if your text boxes in panel1 contain say "15", "25", "14", and "3". txtresult will display them like this "15, 25, 14, 3, "

yousafc# I hope I didn't misunderstand your code, and stefano I hope this makes sense

Ange1ofD4rkness
Posting Whiz in Training
211 posts since May 2010
Reputation Points: 10
Solved Threads: 7
Skill Endorsements: 2

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0854 seconds using 2.69MB