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

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

问题描述

我在数据绑定后将图像添加到 DGV 单元格时遇到问题.

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

这是我的代码:

                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";

数据表是数据库的结果,在第一个 coll 我有 TeX 表达式——我想用MimeTex.dll"为这个表达式生成图像,我知道怎么做,但我不知道如何用图像替换这个 TeX 表达式,
屏幕上是我的原始 DGV,没有图像.

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...

有什么想法吗?TIA屏幕 :http://www.freeimagehosting.net/image.php?66fe2964fe.jpg

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天全站免登陆