如何设置图像数据网格视图单元后的数据绑定? [英] How set image to data grid view cell after data binding?

查看:199
本文介绍了如何设置图像数据网格视图单元后的数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有后数据绑定将图片添加到DGV电池问题



这是我的代码:

  DataTable的标签= conn.searchData(searchTmp); 
bindingSource1.DataSource =标签;
DGV.AllowUserToAddRows = FALSE;

DGV.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
//不显示此colls
DGV.Columns [ZID]可见=假。
DGV.Columns [TID]可见=假。
DGV.Columns [TID2]可见=假。

DataGridViewImageColumn共同=新DataGridViewImageColumn();
System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
的System.IO.Stream文件= thisExe.GetManifestResourceStream(MyApp.Resources.Tx1 [K] .gif要点);
的System.IO.Stream文件2 = thisExe.GetManifestResourceStream(MyApp.Resources.Tx2 [K] .gif要点);



//和其他所有列 - 第一排灰

  BMP位图=新位图(文件); 
co.Image = BMP;

DataGridViewImageColumn IMG =新DataGridViewImageColumn();
图像的图像= BMP;
img.Image =图像;
DGV.Columns.Add(IMG);
img.HeaderText =形象;
img.Name =img目录;

数据表从数据库中,第一科尔
结果,我有TeX的表达 - 我想生成此表达MimeTex.dll的图片,我知道该怎么做,但我不知道如何与图像替换此TeX的表达,在屏幕上搜索
是我生DGV,没有图像。



在最后六行我有代码的一部分用于增加新列,因为我在测试和静态图像的努力如何取代第一行的列文(标题行)从应用程序的资源没有成功...



你知道吗?
TIA
屏:
HTTP:// WWW。 freeimagehosting.net/image.php?66fe2964fe.jpg


解决方案

  DataGridViewImageColumn IC =新DataGridViewImageColumn(); 
ic.HeaderText =图;
ic.Image = NULL;
ic.Name =CIMG;
ic.Width = 100;
DGV.Columns.Add(IC);


的foreach(的DataGridViewRow行DGV.Rows)
{
DataGridViewImageCell细胞= row.Cells [1]作为DataGridViewImageCell;
cell.Value =(System.Drawing.Image对象)Properties.Resources.Icon_delete;
}


I have problem with adding image to DGV cell after data binding.

this is my code:

                DataTable tab = conn.searchData(searchTmp);
              bindingSource1.DataSource = tab;
              DGV.AllowUserToAddRows = false;

              DGV.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);                
              //dont show this colls
              DGV.Columns["zId"].Visible = false;
              DGV.Columns["tId"].Visible = false;
              DGV.Columns["tId2"].Visible = false;

              DataGridViewImageColumn co = new DataGridViewImageColumn();
              System.Reflection.Assembly thisExe;
              thisExe = System.Reflection.Assembly.GetExecutingAssembly();
              System.IO.Stream file = thisExe.GetManifestResourceStream("MyApp.Resources.Tx1[k].gif");
              System.IO.Stream file2 = thisExe.GetManifestResourceStream("MyApp.Resources.Tx2[k].gif");

// and other for all column -- first grey row

              Bitmap bmp = new Bitmap(file);
              co.Image = bmp;

              DataGridViewImageColumn img = new DataGridViewImageColumn();
              Image image = bmp;
              img.Image = image;
              DGV.Columns.Add(img);
              img.HeaderText = "Image";
              img.Name = "img";

Data table is result from databases, in first coll i have TeX expression -- I want generate images for this expression with "MimeTex.dll", I know how do this but I don't know how replace this TeX expression with image,
on the screen is my raw DGV, without images.

on last six lines I have a part of code for add new column because I testing and trying how replace first row columns text (header row) with static images from apps resource without success...

Any idea? TIA screen : http://www.freeimagehosting.net/image.php?66fe2964fe.jpg

解决方案

  DataGridViewImageColumn ic= new DataGridViewImageColumn();
  ic.HeaderText = "Img";
  ic.Image = null;
  ic.Name = "cImg";
  ic.Width = 100;
  DGV.Columns.Add(ic);


  foreach (DataGridViewRow row in DGV.Rows)
  {
    DataGridViewImageCell cell = row.Cells[1] as DataGridViewImageCell;
    cell.Value = (System.Drawing.Image)Properties.Resources.Icon_delete;
  }

这篇关于如何设置图像数据网格视图单元后的数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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