views:

32

answers:

2

I'm a fill datagridview When it opens the second form the value displayed will not

Why?

My code:

// in form1
private bool Method1()
{
    using (var form2 = new frmMain())
    {
        form2.RaiseLoadEvent(EventArgs.Empty);

    }
    return (true);
}

private void frm1_Load(object sender, EventArgs e)
{

    Method1();

    this.DialogResult = DialogResult.Cancel;

}

// in form2

public void RaiseLoadEvent(EventArgs e)
{
    this.OnLoad(e);
}

private void OnLoad(EventArgs e)
{
    this.con = new OleDbConnection(this.ConnectionString());

    string strquery = "select * from english";

    this.dba = new OleDbDataAdapter(strquery, con);

    this.dba.Fill(this.ds);

    this.dataGridView1.DataSource = this.ds.Tables[0].DefaultView;
}

code in Program.cs :

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    frm1 frmsp = new frm1();

    if (frmsp.ShowDialog() == DialogResult.Cancel)
    {
        Application.Run(new frmMain());
    }

}
A: 

Form2 is disposed of. Then you run with a new Form2.

using (var form2 = new frmMain()) 
{ 
    form2.RaiseLoadEvent(EventArgs.Empty); 

} 

... creates and fills in the DataGrivView, but the using() will dispose of the frmMain object.

Then you call...

Application.Run(new frmMain());

which creates an entirely new frmMain().

If your goal is to populate the grid while displaying a splash screen, you need to develop them separatedly. Splash screens show up for some given amount of time, so use a timer to display and then dispose of your splash screen. In the meantime, launch your main form and keep it invisible until the grid is populated.

Les
A: 

The code that I wrote was for the SplashScreen

I want the form to loaded ، then The form2 is displayed

What suggestions do you ?

I want to do this form1.

ehsan_d18