Click here to Skip to main content
15,616,639 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
In my project I have to insert vendor item information.

For that I need dynamic generation of textboxes.
Initially I should have a row of four textboxes and one add button for generating new row of textboxes.

I also have to do some calculations in those textboxes:

Value of 4th textbox = 2textbox value + 3rd textbox

Please help me with this task!

Thank you!
Updated 29-Nov-10 21:51pm
Dalek Dave 30-Nov-10 3:51am    
Edited for Readability.

Well here is a code to dynamically create textboxes:

//On the click event of the button , Write this:

 TextBox myNewTextBox=new TextBox();

 // Assuming you have a panel pnl
Share this answer
Dalek Dave 30-Nov-10 3:51am    
Good Answer, spot on.
Tarun.K.S 30-Nov-10 4:23am    
The value of the fourth TextBox should be set in the TextChanged event of one or more of the TextBoxes that will effect it.

In the Add button's Click event, do the following:

Step 1. Create new TextBoxes:
TextBox[] newRow = new TextBox[]{
     new TextBox(),
     new TextBox(),
     new TextBox(),
     new TextBox()

Step 2. Adjust the properties on each of the TextBoxes to fit your display needs:
newRow[0].Location = new Point(x,y);
newRow[0].Size = new Size(w,h);
newRow[0].Visible = true;

Step 3. Hook the event handlers to the TextBoxes (these event handlers should already exist for the initial four TextBoxes):
newRow[0].TextChanged += new TextChangedEventHandler(TextBox1_TextChanged);
newRow[1].TextChanged += new TextChangedEventHandler(TextBox2_TextChanged);

Step 4. Add to form/control:
Share this answer
Dalek Dave 30-Nov-10 3:52am    
Excellent answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900