use*_*065 5 c# formatting datagridview image cell
我在数据绑定后向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");
Run Code Online (Sandbox Code Playgroud)
//和其他所有列 - 第一个灰色行
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";
Run Code Online (Sandbox Code Playgroud)
数据表是从数据库的结果,在第一科尔,我有TeX的表达-我想生成此表达"MimeTex.dll"的图像,我知道该怎么做,但我不知道如何更换图片的TeX的表达,
对屏幕是我的原始DGV,没有图像.
在最后六行中,我有一部分代码用于添加新列,因为我测试并尝试如何用来自apps资源的静态图像替换第一行列文本(标题行)而没有成功...
任何的想法?TIA屏幕:http://www.freeimagehosting.net/image.php? 66fe2964fe.jpg
小智 13
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;
}
Run Code Online (Sandbox Code Playgroud)