【发布时间】:2015-06-15 13:09:04
【问题描述】:
我有一个DataTable,其中包含以下列:
- 身份证
- 图像索引
- 来源
- 目的地
在我的表单加载事件中,我想用我的DataTable 填充我的DataGridView。但我还希望有一个图像列,根据我的DataTable 上的 ImageIndex 的值显示不同的图像。
我该怎么做?
【问题讨论】:
标签: c# winforms datagridview datatable
我有一个DataTable,其中包含以下列:
在我的表单加载事件中,我想用我的DataTable 填充我的DataGridView。但我还希望有一个图像列,根据我的DataTable 上的 ImageIndex 的值显示不同的图像。
我该怎么做?
【问题讨论】:
标签: c# winforms datagridview datatable
第一步是在属性文件夹下的 Resources.resx 文件中添加图像。然后在 DataGridView 中添加一个 DataGridViewImageColumn。
最后在你的gridview的数据绑定事件上使用这个sn-p。
for (int row = 0; row <= [YourDataGridViewName].Rows.Count - 1; row++)
{
if(gvFiles.Rows[row].Cells["Index of the imageindexcolumn"]).Value = 1)
{
(DataGridViewImageCell)gvFiles.Rows[row].Cells["Index of the imagecolumn"]).Value = Properties.Resources.Picture1
}
else if (gvFiles.Rows[row].Cells["Index of the imageindexcolumn"]).Value = 2)
{
(DataGridViewImageCell)gvFiles.Rows[row].Cells["Index of the imagecolumn"]).Value = Properties.Resources.Picture2
}
}
【讨论】: