I have two forms. Form 1 has a datagridview in side and form 2 has a textbox and a button inside. Value is entered in textbox will be inserted in datagridview after I click the button. I used Show() and ShowDialog() before, but a new form with new data is shown after I clicked button. I also tried Update() and Refresh() but still not working? I need the datagridview refresh itself after I click the button and no new form come out. Anyone can help me? Please....
Here is my code:
Form 1
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dataGridView1.Rows.Add(46.13, 0, 0);
this.dataGridView1.Rows.Add(105.22, 0, 0);
this.dataGridView1.Rows.Add(80.67, 0, 0);
}
public void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form2 newMDIChild = new Form2();
// Set the parent form of the child window.
newMDIChild.MdiParent = this;
// Display the new form.
newMDIChild.Show();
}
Form 2
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FormTest.Form1 frm = new Form1();
frm.dataGridView1.Rows[0].Cells[0].Value = textBox1.Text;
frm.();
}
}
Form 2 Button Click use this Code
private void button1_Click(object sender, EventArgs e)
{
Form frm=(Form)this.MdiParent;
DataGridView dt = (DataGridView)frm.Controls["dataGridView1"];
dt.Rows[0].Cells[0].Value = textBox1.Text;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments