Create Parameterised constructor in form2 or window to which will use the datagridview of another window say window1 or form1 pass your datagridview as parameter from window1 or form1 as below
public partial class Form1 : Form
{
public class AnEntity
{
public string name { get; set; }
public int roll { get; set; }
}
public Form1()
{
InitializeComponent();
List<anEntity> lstEntity = new List<anEntity>();
AnEntity a = new AnEntity();
a.name = "Anis";
a.roll = 90;
lstEntity.Add(a);
a = new AnEntity();
a.name = "Monojit";
a.roll = 19;
lstEntity.Add(a);
a = new AnEntity();
a.name = "Rubel";
a.roll = 18;
lstEntity.Add(a);
dataGridView1.DataSource = lstEntity;
}
private void btnGo_Click(object sender, EventArgs e)
{
Form2 f = new Form2(dataGridView1);
f.ShowDialog();
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form2(DataGridView grdv)
{
InitializeComponent();
label1.Text = "Total Row:" + grdv.Rows.Count.ToString();
}
}