查看数据时查看Loading.gif图像C#

时间:2022-11-11 16:31:36

On a WinForm application, I have a form that contains a GridView, I am filling the GridView by collecting the data from a database. I Have a pictureBox that contains a Loading.gif image. What do i want is to view the PictureBox during retrieving the data from the database.

在WinForm应用程序上,我有一个包含GridView的表单,我通过从数据库收集数据来填充GridView。我有一个包含Loading.gif图像的pictureBox。我想要的是在从数据库中检索数据期间查看PictureBox。

I tried the bellow code, but it did not work...

我尝试了波纹管代码,但它不起作用......

 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/ >download youtube videos

http://soundfrost.org/>下载youtube视频

1 个解决方案

#1


2  

Do your retrieving in another thread and use Dispatcher so that you can access your controls from that thread:

在另一个线程中检索并使用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; 
}));

#1


2  

Do your retrieving in another thread and use Dispatcher so that you can access your controls from that thread:

在另一个线程中检索并使用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; 
}));