在WinForm应用程序中,我有一个包含GridView的表单,我通过从数据库中收集数据来填充GridView。 我有一个包含Loading.gif图像的pictureBox。 我想要的是在从数据库中检索数据时查看PictureBox。
我尝试了波纹管代码,但它没有用......
private void Generate_Button_Click(object sender, EventArgs e) { pictureBox1.Visible = true; { Generate_Button.Text = "Done"; if (conn.State == ConnectionState.Closed) conn.Open(); radGridView1.Columns.Add(new GridViewTextBoxColumn("Account No.")); radGridView1.Columns[0].Width = 85; bool DataAvailable = false; if (MainAccNo_TextBox.Text == "" && CurencyNo_TextBox.Text == "") { if (SeparateBy_DropDownList.Text == "4") { for (int i = 1; i <= 9; i++) { for (int j = 0; j <= 9; j++) { for (int k = 0; k <= 9; k++) { for (int l = 0; l <= 9; l++) { SqlCommand cmd_AccNo = new SqlCommand("Select distinct(AccNo) from JourTrans where AccNo like '" + i + "" + j + "" + k + "" + l + "%'", conn); SqlDataReader reader_AccNo = cmd_AccNo.ExecuteReader(); radGridView1.Rows.Add(i + "" + j + "" + k + "" + l); while (reader_AccNo.Read()) { Accounts.Add(reader_AccNo["AccNo"].ToString()); radGridView1.Rows.Add(reader_AccNo["AccNo"].ToString()); DataAvailable = true; } reader_AccNo.Close(); if (DataAvailable == true) { radGridView1.Rows.Add(""); DataAvailable = false; } else radGridView1.Rows.RemoveAt(radGridView1.Rows.Count - 1); } } } } } } } pictureBox1.Visible = false; }
http://soundfrost.org/&gt;下载youtube视频
答案 0 :(得分:2)
在另一个线程中检索并使用Dispatcher,以便您可以从该线程访问控件:
pictureBox1.Visible = true;
Dispatcher.BeginInvoke(new MethodInvoker(() =>
{
for (int i = 1; i <= 9; i++)
{
//Here I am retrieving data from the database
}
pictureBox1.Visible = false;
}));