如何使用DataGridViewImageColumn增强DataGridView的性能 [英] How to enhance performance of DataGridView with DataGridViewImageColumn

查看:65
本文介绍了如何使用DataGridViewImageColumn增强DataGridView的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个DataGridView,其中包含其中一列为DataGridViewImageColumn的列。但是当我打开包含停靠DataGridView的表单时,需要很长时间才能加载。



我的第一个解决方案是将DataGridView设置为VirtualMode,尽管有一个主要的表单加载速度的改进(现在表单立即加载,但你可以看到DataGridView逐个创建单元格)。



无论如何都要加速加载DataGridView需要多长时间?



PS



在VirtualMode的CellValueNeeded事件中DataGridView我计算创建DataGridViewTextBoxColumn(00:00:00)和DataGridViewImageColumn(00:00:00.0468001)所需的时间



我从资源中获取图像C#项目中的文件夹,每个图片的尺寸为23x23。



更多背景...

我所拥有的是5个不同的图像。每个都引用当前在行中定义的项目的差异状态。我将始终使用其中一个图像,从不在维护程序计划中包含超过5个图像或少于这5个图像。



进度...每次我声明5个Image对象时,我都不会从资源文件夹中获取图像,而是将其用作图像。现在的时间如下来创建单元格......一个DataGridViewTextBoxColumn(00:00:00)和DataGridViewImageColumn(00:00:00.0370001)

Ok so I have a DataGridView that contains columns one of them being a DataGridViewImageColumn. But when I open the form containing the docked DataGridView it takes a long time to load.

My first solution was to set the DataGridView to VirtualMode and although there was a major improvement on the speed the form takes to load (now the form loads instantly but you can see the DataGridView creating the cells one by one).

Is there anyway to speed up the time it takes the DataGridView to load?

P.S.

In the CellValueNeeded Event of the VirtualMode DataGridView I timed the time it takes to create a DataGridViewTextBoxColumn ( 00 : 00 : 00) and DataGridViewImageColumn (00 : 00 : 00.0468001)

I get my images from the resource folder in the C# project and each image has dimensions 23x23.

Little more background...
What I have is 5 difference images. Each referring to a difference status on the item currently defined in the row. I will always use one of these images and never in the maintenance of the program plan to include more than 5 images or less than these 5 images.

Progress... Instead of getting the images from the resources folder every time I have declared 5 Image objects and I am using then as the images. The time now is as follows to create the cells...a DataGridViewTextBoxColumn ( 00 : 00 : 00) and DataGridViewImageColumn (00 : 00 : 00.0370001)

推荐答案

这取决于关于你的数据。你真的无法加速行和列本身的生成和渲染。



但是,如果你从数据库中获取了巨大的图像将它们渲染在一个小区域,你就是在浪费时间,因为你正处理很多你不使用的图像数据。



例如,你的图像列以100x50像素显示图像,但您从数据库中获取的图像为5000x2500,您浪费了大量时间来传输和渲染数据而您没有使用。



解决方案很简单。在数据库中添加另一列,其中包含您的网格可以使用的图像的缩略图副本,而不会产生额外的开销。
That depends on your data. You really can't speed up the generation and rendering of the rows and columns themselves.

But, if you're getting images out of the database that a huge and rendering them in a small area, you're wasting time because you're processing a lot of image data you're not using.

For example, your image column is showing images in 100x50 pixels, but the images you're getting from your database are 5000x2500, you're wasting a lot of time transferring and rendering data and you're not using.

The solution to that is simple. Add another column to your database that has "thumbnail" copies of your images in it that your grid can use without all the extra overhead.


我忘记了这篇文章,但最后标记了它作为解决,我将说以下内容。对于我显示的一些数据,我必须对数据进行一些计算,并对写得不好的算法进行一些计算,这会减慢我在datagridview上的加载时间。因此,在重写算法后,它完美地工作。感谢每个人的投入,非常感激。
I forgot about this post but just to finally marked it as solve I will say the following. For some of the data that I displayed I had to do some calculations with the data, and do to a poorly written alogrithm, that slowed down my load time on the datagridview. So after rewriting the algorithm it worked perfectly. Thank for everyones input, much appreciatted.


这篇关于如何使用DataGridViewImageColumn增强DataGridView的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆