读书人

DataGridView中图片闪动的有关问题

发布时间: 2013-12-10 15:05:55 作者: rapoo

DataGridView中图片闪动的问题
在Winform窗体中,使用DataGridView控件DataGridViewImageColumn列来显示图片,问题是显示的图片不听的闪动,请教有什么方法可以解决这个问题。

绑定图片的方法如下:
在DataGridView中添加DataGridViewImageColumn 图片列
DataGridViewImageColumn img = new DataGridViewImageColumn();
img.HeaderText = "产品图片";
img.ImageLayout = DataGridViewImageCellLayout.Zoom;
img.Width = 130;
dgvProduct.Columns.Add(img);

在DataGridViewCellFormatting方法中进行图片的绑定
((DataGridViewImageCell)this.dgvProduct.Rows[e.RowIndex].Cells[12]).Value = GetImage(strPath);

麻烦大家帮忙看下如何解决图片闪动的问题,谢谢
[解决办法]
不要在DataGridViewCellFormatting设置列的值啊,因为每当DataGridView发生重绘时便执行一次,这样肯定会闪烁了

以下是从数据源绑定的


DataTable dt = new DataTable();
dt.Columns.Add("pic",typeof(Image));
for (int i = 0; i < 5; i++)
{
DataRow row = dt.NewRow();
row["pic"] = GetImage(strPath);
dt.Rows.Add(row);
}

DataGridViewImageColumn img = new DataGridViewImageColumn();
img.HeaderText = "产品图片";
img.ImageLayout = DataGridViewImageCellLayout.Zoom;
img.Width = 130;
img.DataPropertyName = "pic";
dgvProduct.Columns.Add(img);
dgvProduct.AutoGenerateColumns = false;
dgvProduct.DataSource = dt;

读书人网 >C#

热点推荐