Click here to Skip to main content
15,741,892 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
C#
foreach (Control c in panel1.Controls)
{


    if (c is TextBox)
    {
        TextBox txt = (TextBox)c;

        string msg = txt.Text;
        MessageBox.Show(msg);


    }

}
Posted

1 solution

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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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)



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