Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
i have created text box dynamically. i am able to retrieve text value from text box.how to store this value in array?? is it possible?
 
code:
            foreach (Control c in panel1.Controls)
            {
 
               
                if (c is TextBox)
                {
                    TextBox txt = (TextBox)c;
 
                    string msg = txt.Text;
                    MessageBox.Show(msg);
 
                   
                }
 
            }
Posted 26-Sep-12 4:28am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Just define an array in the appropriate scope and add the text from the textbox to it. ie. YourArrayObject.Add(YourTextValue);
I would highly suggest not using and Array[], but rather a List.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 26-Sep-12 11:15am
   
That's correct, my 5. I would only add that it could be any kind of container (generic List, etc.), and it should be defined and populated at the moment of "dynamic creation" of the controls. Generally, there is not such thing as a kind of mysterious "non-dynamic". The designer? No difference, but better don't use the designer to create a whole array of something or just many controls -- this is pure manual work, unlike your own code.
--SA

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

  Print Answers RSS
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 166
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,081
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100