Follow this steps it may help you.
1. declare a constructor and a public variable in the form which you want to open.
public string strvalue = string.Empty;
public Form2()
{
InitializeComponent();
}
public Form2(string str)
{
strvalue = str;
InitializeComponent();
}
2.Open form2 like this
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1)
{
if (e.ColumnIndex != 1)
{
if (!string.IsNullOrEmpty(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()))
{
string strValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
Form2 _Form2 = new Form2(strValue);
_Form2.ShowDialog();
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = _Form2.strvalue;
dataGridView1.Refresh();
}
}
}
}
3. Close form2 on a event and set value in
private void button1_Click(object sender, EventArgs e)
{
strvalue = textBox1.Text;
this.Close();
}