简体   繁体   中英

Not fill datagridview

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());
    }

}

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM