I have a window form in which button1 , when the usercontrol is clicked, the code is dynamically added, this
int c = 0; private void button1_Click(object sender, EventArgs e) { int v; v = c++; panel1.VerticalScroll.Value = VerticalScroll.Minimum; UserControl1 us = new UserControl1(); us.Name = "us" + v; us.Location = new Point(50, 5 + (30 * v)); us.Tag = btn; panel1.Controls.Add(us); }
that usercontrol contains 4 controls 2 combobox and 2 text fields
ie combobox1 combobox2 textbox1 textbox2
there are 4 text fields that are in the same form as
still-textbox1, still-textbox2, still-textbox3, still-textbox4
another button2 , there it will transfer text to comboboxes and texboxes, which is oldcombobox1 oldcombobox2 oldtextbox1 old textbox2
when button1 double-clicks, it will add two user controls to the form. I want to transfer text in this format
oldcombobox1.text = still-textbox1.text + "," + combobox1.text (which is dynamically generated) + "," + combobox1.text (which is dynamically generated), etc. all combobox1 from a user control that is dynamically added)
oldcombobox2.text = still-textbox2.text + "," + combobox2.text (which is dynamically generated) + "," + combobox2.text (which is dynamically generated), etc. all combobox2 from a user control that is dynamically added)
oldtextbox1.text = still-textbox3 + "," + textboox1.text (which is dynamically generated) + "," + textbox1.text (which is dynamically generated), etc. all text field1 from the user control, which is added dynamically)
means the file is still-textbox1.text = first and when dynamic user control is added three times, it will contain 3 times combobox1, then
oldcombobox1 should contain
Fisrt, combobox1.text, combobox1.text, combobox1.text
I made this code but it does not work
foreach (Control ctrl in panel1.Controls) { if (ctrl is UserControl) { UserControl1 myCrl = ctrl as UserControl1; oldcombobox1.text = still-textbox1.text + "," + myCrl.comboBox1.Text; oldcombobox2.Text =still-textbox2.text + "," + myCrl.comboBox2.Text; oldtextbox1.Text = still-textbox3.text + "," + myCrl.textBox1.Text; oldtextbox2.Text.Text = still-textbox4.text + "," + myCrl.textBox2.Text; } }