Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
Updated 4-Jan-13 6:40am
v3

1 solution

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.
 
Share this answer
 
Comments
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..
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
sariqkhan 4-Jan-13 14:44pm    
http://www.codeproject.com/Questions/521783/howplustoplustransferplustheplustextplusfromplusdy
sir can you help me here please if you can

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