在DataGridView单元中动态显示图像 [英] Display Image in DataGridView Cell dynamically

查看:161
本文介绍了在DataGridView单元中动态显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我有窗口形式的DataGridView.有一列与文本行"和图像行"绑定.列类型为GridViewTextBoxColumn.
但是我的要求是Value要么是Text格式,要么是Image格式.如果是文本格式,则显示,但如果是图像格式,则如何在同一列中绑定该图像.

例如

Hi friends

I have DataGridView in Window form. There is one column which is binding with Text row and Image Row. Column Type is GridViewTextBoxColumn.
But my requirement is that Value is either in Text format or Image format. If it is Text Format then it display but if it is image format then how to bind that image in same column.

For example

foreach (MyClassObject q in qList)
{
   if (q.IsImage){
         gridMC.Rows[c].Cells[1].Value = q.ImageValue; // Image Object
   }else{
         gridMC.Rows[c].Cells[1].Value = q.TextValue;
   }
}
//gridMC is my GridView



谢谢
Imrankhan



Thanks
Imrankhan

推荐答案

为什么不保留2列.一个用于文本,另一个用于图像.根据您的要求,您只需更改可见性即可.
如果要显示图像列,则将其可见性更改为true,将文本列更改为false,反之亦然.
Why don''t you keep 2 columns. One for text and other for image. And depending upon your requirement you just change the visibility.
if you want to show image column then change its visibility to true and text column to false and vice-versa.


在DataGridView中,转到属性并添加列",此时您可以选择Datagridimagecolumn .您将获得图像.
Hi In DataGridView go Propertys and add column at that time columntype u can choose Datagridimagecolumn. u will get image.


几种方法
1.购买适合您需求的基础设施wingrid等商业组件
2.搜索一个名为"textimagecolumn"的东西,一个家伙已经以这种方式实现了一个(也许不合适的)解决方案...
3.编写自己的自定义列类,例如覆盖绘画事件,自己绘制一个绘画单元
4.等到微软公司遇到这个缺陷
5.或同时死亡;-)

我自己必须为此奋斗.这种笨拙,不便实现datagridview的行为真是太可惜了.
the few ways
1. go and get a commercial component like infragistics wingrid that fits your needs
2. search for something called "textimagecolumn", a some guy has implemented a (maybe not suitable) solution in this manner...
3. write your own custom column class, e.g. overwrite the paint event an paint cells yourself
4. wait till the microsoft guys come across this flaw
5. or die meanwhile ;-)

I have to struggle with this myself. It''s a damn shame this clumsy, inconvenient implementation of the datagridview.


这篇关于在DataGridView单元中动态显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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