动态更改DataGridViewImageCell的图像不适用于表单加载 [英] Dynamically Changing The Image of a DataGridViewImageCell Isn't Working On Form Load

查看:62
本文介绍了动态更改DataGridViewImageCell的图像不适用于表单加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DataGridViewImageColumn,它应该仅显示某些行的图像.在将类的通用列表绑定到我的数据网格之后,我遍历每一行,并用图像更新图像单元格,该图像是需要该图像的行的嵌入式资源.如果表单已完全加载,则效果很好.但是,当我在表单加载中尝试此操作时,图像没有显示出来吗?我也无法执行更简单的操作,例如在表单加载时更改行背景颜色.加载表单后,是否应该在其他事件中执行此逻辑?任何帮助将不胜感激.

对于 整数 = 0 dgvRoles.Rows.Count-1

For i As Integer = 0 To dgvRoles.Rows.Count - 1

imageStream As System.IO.Stream = 没什么

Dim imageStream As System.IO.Stream = Nothing

imageStream = Me .GetType().Assembly.GetManifestResourceStream( ""MyApplication.Timer.png"" )

 

如果 ( TypeOf dgvRoles.Rows(i).Cells(dgvRoles.Columns.Count-1) DataGridViewImageCell) 然后

If (TypeOf dgvRoles.Rows(i).Cells(dgvRoles.Columns.Count - 1) Is DataGridViewImageCell) Then

dgvRoles.Rows(i).Cells(dgvRoles.Columns.Count-1).Value = Image.FromStream(imageStream)

dgvRoles.Rows(i).Cells(dgvRoles.Columns.Count - 1).Value = Image.FromStream(imageStream)

imageStream.Close()

imageStream.Close()

结束 如果

 

下一步

Next

推荐答案

I有同样的问题.前两行图像正确显示,但后续行却未正确显示.它只是呈现为红色X.它只是在Form_Load事件期间发生.
代码摘录如下:-

 

I'm having the same issue. The first two rows image rendered correctly but not the subsequent rows. It just rendered as a red X. It just happened during Form_Load event.
Code excerpt as below:-

 

私有 dgvqa_Row Transactions( 对象 DataGridViewRowwegosEventArgs e)

{

private void dgvqa_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)

{

 

如果 (例如,RowIndex> = 0)

{

if (e.RowIndex >= 0)

{

 

DataGridViewImageCell span> iconCell =( )dgvqa.Rows [e.RowIndex] .Cells [ "ccIcon" ];

 

DataGridViewImageCell iconCell = (DataGridViewImageCell)dgvqa.Rows[e.RowIndex].Cells["ccIcon"];

 

DataGridViewTextBoxCell iconString =( )dgvqa.Rows [e.RowIndex] .Cells [ "ccIconString" ];

 

DataGridViewTextBoxCell iconString = (DataGridViewTextBoxCell)dgvqa.Rows[e.RowIndex].Cells["ccIconString"];

 

如果 (iconString.Value!=系统. DBNull .Value)

{

if (iconString.Value != System.DBNull.Value)

{

 

如果 (iconString.Value!= )

{

if (iconString.Value != null)

{

 

图片 iconPng =( )WqWidget. ImageHelper )iconString.Value);

iconCell.ValueType = iconPng.GetType();

iconCell.ValueType = iconPng.GetType();

iconCell.Value = iconPng;

iconCell.Value = iconPng;

}

}

}

}


这篇关于动态更改DataGridViewImageCell的图像不适用于表单加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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