Click here to Skip to main content
11,709,537 members (34,813 online)
Rate this: bad
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 to store this value in array?? is it possible?

foreach (Control c in panel1.Controls)

    if (c is TextBox)
        TextBox txt = (TextBox)c;
        string msg = txt.Text;

Posted 26-Sep-12 4:28am

1 solution

Rate this: bad
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.
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.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 530
1 OriginalGriff 250
2 Peter Leow 229
3 Maciej Los 185
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2015
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