'How to add content to DataGridView from another form?
I have Main Form which connected with two other forms by buttons(Content Adding Form and Form with DataGridView). Form with DataGridView must be without button (which go over to Content Adding Form).
Content Adding Form:
private void button1_Click(object sender, EventArgs e)
{
FormDataGridView main = this.Owner as FormDataGridView;
if (main != null)
{
DataRow nRow = main.databaseDataSet.Tables[0].NewRow();
int rc = main.dataGridView1.RowCount + 1;
nRow[0] = rc;
nRow[1] = textBox1.Text;
nRow[2] = textBox2.Text;
nRow[3] = textBox3.Text;
nRow[4] = textBox4.Text;
main.databaseDataSet.Tables[0].Rows.
Add(nRow);
main.studentsTableAdapter.Update(main.databaseDataSet.students);
main.databaseDataSet.Tables[0].AcceptChanges();
main.dataGridView1.Refresh();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
}
Main Form:
private void button2_Click(object sender, EventArgs e)
{
ContentAdding add = new ContentAdding();
add.Show();
}
private void button1_Click(object sender, EventArgs e)
{
FormDataGridView view = new FormDataGridView();
view.Show();
}
Solution 1:[1]
It should be sufficient to pass from main form to others your main.databaseDataSet.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wojciech Gebczyk |
