如何在datagridview使用C#.net windows应用程序从数据库加载数据时显示图像? [英] How to display image while datagridview load data from database using C# .net windows application?
本文介绍了如何在datagridview使用C#.net windows应用程序从数据库加载数据时显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我在C#.net windows应用程序中将数据从数据库检索到DataGridView时使用此代码显示图像。: -
Hello,
I am using this code for display image while retrieve data from database to DataGridView in C# .net windows application.:-
pictureBox1.Visible = true; // it's a swf loading image.
dataGridView1.ReadOnly = true;
SqlConnection con = new SqlConnection(cnString1);
con.Open();
dadapter = new SqlDataAdapter("select * from BAN_ItemDataMaster where [Signal Code]='HOME'", con);
data = new DataTable();
dadapter.Fill(data);
dataGridView1.DataSource = data;
con.Close();
pictureBox1.Visible = false;
但我的代码运行不正确。
我的图像没有显示。
我想在数据库加载时显示图像。
请帮帮我,怎么可能?
提前致谢。
Ankit Agarwal
软件工程师
But my code doesn't run properly.
My image did not display.
I want to display image while database load.
Please help me, How could be possible?
Thanks in advance.
Ankit Agarwal
Software Engineer
推荐答案
有趣的部分介于PictureBox1.Visible = true;
和PictureBox1.Visible = false;
。
它都在主线程(也就是GUI线程)中运行。因此GUI线程没有时间重新绘制GUI,这是它的主要职责。
将数据库内容分离到另一个线程,以便GUI线程可以显示(后来隐藏)PictureBox1。
The interesting part is betweenPictureBox1.Visible = true;
andPictureBox1.Visible = false;
.
It's all running in the main thread (a.k.a. GUI thread). Therefore GUI thread doesn't have time to repaint the GUI, which is its main duty.
Separate out the database stuff to another thread, so that GUI thread can display (and later hide) PictureBox1.
这篇关于如何在datagridview使用C#.net windows应用程序从数据库加载数据时显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文