Click here to Skip to main content
12,885,022 members (29,894 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
i have a windows formin which there is a button1 clicking
the button a user control is added dynamically on a panel1.
in that usercontrol there are 4 control
combobox1, combobox2, textbox1,textbox2
and there is 4 more control on the windows form which is phonemanu phonemo imietextbox and faultextbox
one more button2 when button is click it transfer
all the text to a new form which is newcustomer
i want that in this form
new.phonemanu must be (phonemanu,combobox1,combobox1,etc all the dynmaically generated combobox1)
new.phonemo must be (phonemo,combobox2,combobox2,etc all the dynmaically generated combobox2)

i have generated this code but it only shows (phonemanu.text , last generated combobox1)
and all the middle combobox text is not add.. why i dont know

this is my code

newcustomer new1 = new newcustomer();
                foreach (Control ctrl in panel1.Controls)
                    if (ctrl is UserControl1)
                        UserControl1 myCrl = ctrl as UserControl1;
                        new1.phonemanu.Text = phonemanu.Text + "," + myCrl.comboBox1.Text;
                        new1.phonemo.Text = phonemo.Text + "," + myCrl.comboBox2.Text;
                        new1.imeitextbox.Text = imeitextbox.Text + "," + myCrl.textBox1.Text;
                        new1.faulttextbox.Text = faulttextbox.Text + "," + myCrl.textBox2.Text;
Posted 4-Jan-13 5:52am
Updated 4-Jan-13 6:40am

1 solution

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

Solution 2

If they are dynamically generated, then they won't have properties, right ? In general, exposing controls like this is bad. Expose a method that looks up the dynamic controls, and returns the text you want returned.
shaikh-adil 4-Jan-13 14:18pm
can you code and explain?? and in my project i dont want any security then can you simply how can i obtain in simple..
sariqkhan 4-Jan-13 14:44pm
sir can you help me here please if you can
Christian Graus 4-Jan-13 17:23pm
You don't ever access the controls on your user control. You call a method. You need to do this anyhow, because you need to look up this dynamic control and get values from it. But, it's also best practice

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2017
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