Passing data between forms has been asked many times. The easiest way is to use a custom property to pass data or a reference to control to hold the data.
public partial class Form3 : Form // This is your Form1
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 oForm; // This is your Open & Load Excel form
oForm = new Form2();
oForm.ExcelView = this.dataGridView1; // Pass this form's DGV to be filled
oForm.ShowDialog();
oForm = null; // Dispose Excel form
}
}
// This is your Form2
public partial class Form2 : Form
{
public DataGridView ExcelView { get; set; }
public Form2()
{
InitializeComponent();
}
// Add code to open Excel file and load data to ExcelView
private void button1_Click(object sender, EventArgs e)
{
this.Close(); // Return to calling form
}
}
I hope this helps.
Teme @ windevblog.blogspot.com