Click here to Skip to main content
15,914,780 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
I want to create Textbox's dynamically in my windows form with every textbox_leave event.
For example ..

created dynamically
Textbox1
leave event fire on textbox1
Texbox2 is created
leave event fire on textbox2
textbox3 is created
.
.
.
n number of textbox created

unmlimited textboxs is created until user don't want to fire leave event.
Posted
Comments
BillWoodruff 2-Feb-14 6:51am    
That's a very strange design: does each TextBox created have the same location as the previous TextBox created, or do you plan to lay them out in some arrangement so they don't overlap ?

Some information about the "bigger picture" goals of your application would be useful.
varuncodee 2-Feb-14 7:30am    
yes sir that's very strange design but i can't find any other idea.
Sir actually i am developing school project, my project is to develop software for retail shop where counter person can feed(sell) any number of item .
Coming to my project if i place textboxs on my form at design time it will fix the number of item to be sell.
Please suggest some idea or code.. thanks for your reply
BillWoodruff 2-Feb-14 7:43am    
Ideally, I think you'd have a database of items-in-stock, with their current prices. When a customer came to the register, you'd enter (or scan in) the id codes of each item, and then a ListView (or GridView, or some other Control) on your Main Form would be populated with the items being sold, their price, sales tax, etc.

I would expect to see you able to modify a transaction before it's "finalized," add more items before its finalized, cancel a transaction, etc. And it would be good that when a transaction is completed the same database (or another) is updated with amount received, items sold, etc.

In other words, I'd try to model what really happens in most retail shops.

C#
private void btnText1_Click(object sender, EventArgs e)
{
     TextBox txtBox2 = new TextBox();
     txtBox2.Name = "two";
     txtBox2.Text = "two";
     Controls.Add(txtBox);
}


You can add events to the dynamic textbox as well.
 
Share this answer
 
sir, there is a good friend of your's and you almost forgot to visit him before asking the question here. His name is "Google" :laugh try this link will help you in exploring answers http://www.lmgtfy.com/?q=How+to+create+Textbox+dynamically+in+c+sharp[^]
 
Share this answer
 
Comments
Abhijit Ghosh (Subho) 23-Oct-14 6:02am    
This is excellent. I didn't know about this one.
C#
TextBox[] txtTeamNames = new TextBox[teams];
for (int i = 0; i < txtTeamNames.Length; i++) {
  var txt = new TextBox();
  txtTeamNames[i] = txt;
  txt.Name = name;
  txt.Text = name;
  txt.Location = new Point(172, 32 + (i * 28));
  txt.Visible = true;
}
 
Share this answer
 
Hi,
Go through these -
dynamic-controls-cs.htm[^]
 
Share this 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