There are 2 forms. On form 1, there is a table and a button, by pressing which the second datagridview should be filled. When both grids are on the same form, then everything works fine. And how can I make one grid and one button on form 1 and the second form with grid opens on pressing the button and it fills in the second form?
private void button2_Click(object sender, EventArgs e) { Square(); } public void Square() { int n = t1DataGridView.SelectedRows.Count; string[] labels = new string[n]; DataTable dt = new DataTable(); for (int i = 0; i < n; i++) { labels[i] = Convert.ToString(t1DataGridView.SelectedRows[i].Cells[0].Value); dt.Columns.Add(labels[i]); dt.Rows.Add(); } dataGridView1.DataSource = dt; for (int i = 0; i < n; i++) { dataGridView1.Rows[i].HeaderCell.Value = labels[i]; } }