Alynson Torres

Alynson Torres

  • 1.6k
  • 149
  • 2.1k

Pass data between forms, to DataGridView within multiple containers

Dec 1 2020 11:04 AM
Hello everyone, a lot of greetings and thank you very much to everyone who takes the time to see this publication and thanks to anyone who can help me.
 
I am trying to pass data from two textboxes that I have in Form2, here I put the button code, but it gives me an error.
 
See who can help me.
 
In Form1 I have a DatagridView, it is where I want to pass the data, but the path gives me an error The DatagridView is inside a TabPanel1, contained in the TapControl1, this in turn you are inside a Panel1 of a SplitContainer1.
 
  1. private void btnEnter_Click(object sender, System.EventArgs e)  
  2. {  
  3.     Form1 dato = new Form1 ();  
  4.     foreach (Form crl in Application.OpenForms)  
  5.     {  
  6.         if (crl.Name == " Form1 ")  
  7.         {  
  8.             dato = (Form1)crl;  
  9.             dato.splitContainer1.Panel1.TabControl1.tabPage1.DataGridView1.Rows.Add(txtName.Text, txtCity.Text); 
  10.   
  11.             this.Close();  
  12.             break;  
  13.         }  
  14.     }
  15. }  

Answers (2)