我在数据绑定后将图像添加到 DGV 单元时遇到问题。
这是我的代码:
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");
// 以及所有列的其他 -- 第一个灰色行
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,没有图像。
在最后六行中,我有一部分用于添加新列的代码,因为我测试并尝试如何用应用程序资源中的静态图像替换第一行列文本(标题行),但没有成功......
任何想法?
TIA
屏幕 :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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)