0
我是填充datagridview當它打開第二個窗體時,顯示的值不會未填充datagridview
爲什麼?
我的代碼:
// 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;
}
//在窗口2
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;
}
代碼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());
}
}
,我寫的代碼是爲閃屏
我想要表單加載,然後顯示form2
你有什麼建議嗎?
我想要做這個form1。
代碼在那裏,但事件未在您的代碼中分配。這些事件是否在您的GUI中連接起來? – jp2code 2011-09-07 18:41:37