如何将循环图标加载到字段DatagridView? [英] How to load at loop icon to field DatagridView?
本文介绍了如何将循环图标加载到字段DatagridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好!
我从实体查询格式化DatagridView。
现在我有代码:
Hello!
I format DatagridView from Entity query.
Now I have code:
List<Cards.Model.Cards> list = new List<Cards.Model.Cards>();
DateTime timeNow = DateTime.Now;
foreach (var obj in BLL.Cards.GetListCards())
{
Cards.Model.Cards qwe = new Cards.Model.Cards();
DateTime timeEnd = BLL.Cards.UnixTimeStampToDateTime(obj.EndDay);
SetStatusIcon (timeEnd < timeNow ? 1 : 0);
//qwe.Status = timeEnd < timeNow ? 1 : 0;
qwe.IdUser = obj.IdUser; //this is column name
qwe.Mobile = obj.Mobile;
qwe.Username = obj.Username;
qwe.StartDayD = BLL.Cards.UnixTimeStampToDateTime(obj.StartDay);
qwe.EndDayD = timeEnd;
list.Add(qwe);
}
ListCards.DataSource = list;
And function, that change image path and add to Grid image:
private void SetStatusIcon(int status)
{
DataGridViewImageColumn img = new DataGridViewImageColumn();
string path = status == 1 ? "Active.png" : "NoActive.png";
string imagepath = "D:\\""+ path;
Image image = Image.FromFile(imagepath);
img.Image = image;
ListCards.Columns.Add(img); //want here to add field with icon for every row of datagridview
img.HeaderText = "Image";
img.Name = "img";
}
我的目标是:设置一列Image并为datagridview的每一行添加一个具有任何状态的字段图像(Active.png,NoActive.png)
我实际上花了很多时间,所以我请求你帮忙。
谢谢!
我试过了在我填满网格之后也会这样做:
My goal is: Set one column Image and for every row of datagridview add one field image with any status (Active.png, NoActive.png)
I actually spent a lot of time so i requested you for help.
Thank you!
I tried also make such after i get filled grid:
foreach (DataGridViewRow row in ListCards.Rows)
{
DataGridViewImageCell cell = row.Cells[1] as DataGridViewImageCell;
cell.Value = (System.Drawing.Image)Properties.Resources.Active; //Here return error: Object reference not set to an instance of an object.
}
另一种我找不到的方法
Another way i did not find
推荐答案
示例:
Hi,
Example:
private void createGraphicsColumn()
{
Icon treeIcon = new Icon(this.GetType(), "tree.ico");
DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
iconColumn.Image = treeIcon.ToBitmap();
iconColumn.Name = "Tree";
iconColumn.HeaderText = "Nice tree";
dataGridView1.Columns.Insert(2, iconColumn);
}
检查这个^ 链接了解更多详情。
干杯,
JAFC
Check this^ link for more details.
Cheers,
JAFC
这篇关于如何将循环图标加载到字段DatagridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文