Pass data from textbox in form1 to datagridview in other form

Satyapriyanayak
Posted by Satyapriyanayak under C# category on | Points: 40 | Views : 4236
Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace write_to_datagrdiview_from_form2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public Form1(string myString)
{
InitializeComponent();

if (myString != null)
dataGridView1.Rows[0].Cells[0].Value = myString;
}



private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.ShowDialog();

}
}
}


Form2.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace write_to_datagrdiview_from_form2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
new Form1().Close();
}

private void button1_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1(textBox1.Text);
frm1.ShowDialog();
}



}
}

Comments or Responses

Login to post response