How set image to data grid view cell after data binding?
Asked Answered
T

2

7

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

Tigress answered 3/5, 2011 at 23:45 Comment(0)
Z
16
  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;
  }
Zimmerman answered 9/5, 2011 at 13:17 Comment(0)
E
1

simply you can write: DGV.CurrentRow.Cells[1].Value = Properties.Resources.Icon_delete;

Electrophysiology answered 29/10, 2021 at 2:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.