Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.20/5 (2 votes)
When I put a number(such as 32) in a TextBox will create 32 TextBox in another Panel;After Created,if I want to delect 16 TextBox,then remain 16 TextBox.How to implement this function? Can you show me a demo?Thank you!
Posted
Comments
Andy Lanng 7-May-15 10:22am    
Too many ways to achieve this. Try to narrow it down and explain what you need it for and what you have tried

Thanks
Did you search?
Wastedtalent 7-May-15 10:23am    
Are you using code behind or MVVM would be useful to know to start?
Sinisa Hajnal 8-May-15 2:49am    
Did you try to find the solution online? Did you try something yourself and got stuck? If so, what is the problem? Show the code you did and which part of it doesn't work.

1 solution

You could do something like this

C#
public void CreateTextBoxes(StackPanel target, int number)
{
   if (target.Children.Count < number)
   {
      for (int i=target.Children.Count; i< number; i++)
      {
          TextBox tx = new TextBox;
          target.Children.Add(tx);
      } 
   }
   else
   {
          while (target.Children.Count > number)
          {
              target.Children.RemoveAt(target.Children.Count - 1);
          }
   }
}
 
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