如何在C#windows窗体应用程序中的gridview列中加载图标? [英] How to load icons in gridview columns in C# windows form application?
本文介绍了如何在C#windows窗体应用程序中的gridview列中加载图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于Ex:
我必须在gridview的前两列中加载图标。那应该改变它的真实时的图标,当它是假时显示不同的图标。
有人能给我点子吗?我怎样才能完成这项任务!
急需解答。
谢谢......! br />
我尝试了什么:
实际上,我是c#的新手。所以我正在找人帮我解决这个问题...
谢谢
For Ex:
I have to load icons in 1st two columns in a gridview. That should change the icons when its true, and when it is false show different icon.
Can anyone give me idea? how can i achieve this task!
Much needed Answer.
Thank you...!
What I have tried:
Actually, I am newbie to c#. so I am looking for someone to help me out from this...
thanks
推荐答案
使用DataGridViewImageColumn [ ^ ]你可以创建它。 />
将相关图像添加到资源文件夹如何:添加或删除资源 [ ^ ]
using DataGridViewImageColumn [^] you can create it.
Add the relevant images to the resources Folder How to: Add or Remove Resources[^]
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
dataGridView2.Columns.Add(imageCol);
for (int i = 0; i < dataTable.Rows.Count; i++)
{
var flag = dataTable.Rows[i]["BooleanColumn"].ToString().ToLower() == "true";
if (flag)
dataGridView2.Rows[i].Cells[0].Value = WindowsFormsApplication1.Properties.Resources.image1;
else
dataGridView2.Rows[i].Cells[0].Value = WindowsFormsApplication1.Properties.Resources.image2;
}
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;
}
这篇关于如何在C#windows窗体应用程序中的gridview列中加载图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文