Create an event in Form2, and handle it in Form1.
When you click the button in Form2, package the data and add it to a custom EventArgs which you pass with the event when you signal it.
In Form1, when the event occurs, read the EventArgs in the handler and add it to the DataGridView as a new row.
Form2:
public partial class frmOther : Form
{
public frmOther()
{
InitializeComponent();
}
public event EventHandler<ChangedArgs> Changed;
private void butGo_Click(object sender, EventArgs e)
{
EventHandler ch = Changed;
if (ch != null)
{
ch(this, new ChangedArgs(tbData.Text));
}
}
}
public partial class ChangedArgs : EventArgs
{
public string strData;
public ChangedArgs(string str)
{
strData = str;
}
}
Form1:
frmOther otherForm = new frmOther();
private void frmTextBox_Load(object sender, EventArgs e)
{
otherForm.Changed += new EventHandler<ChangedArgs>(Changed);
otherForm.Show();
}
private void Changed(object sender, ChangedArgs e)
{
if (e != null)
{
string myDataFromTheOtherForm = e.strData;
}
}