vb.net - VB.NET:将datagridview中的文本列转换为图像列并根据文本设置图标
问题描述
我 VB.net,我有一个 datagridview,它显示了数据库查询的一些结果。为了生成它,我执行了一些 sql 查询并将数据写入数据表。然后将该表链接到 dgview
dg_data.DataSource = SqlData.DefaultView
现在,一列可以包含某些(固定和预定义)字符,描述使用我的应用程序处理的事件的某种状态。我想用更直观的图标替换这些字符。
我设法使它工作,但仅在包含根据另一列 (11) 代码字符的图像的新的另一列 (12) 中。但是,我想用那个字符替换列并且只显示图像。这就是我所拥有的:
'Add new image column:
Dim imgcol As New DataGridViewImageColumn()
dg_data.Columns.Add(imgcol)
imgcol.HeaderText = "Status"
imgcol.Name = "img"
imgcol.DataPropertyName = "img"
With dg_data
.Columns("img").DisplayIndex = 12
.Columns("img").Width = 20
End With
' Load images from Resources
Dim report_filed As Image = My.Resources.report_filed
Dim report_due As Image = My.Resources.noreport
Dim attention As Image = My.Resources.attention
' Assign correct icon for certain character in status column (example for "!")
For i As Integer = 0 To SqlData.Rows.Count - 1
If dg_data.Rows(i).Cells(11).Value.ToString = "!" Then
dg_data.Rows(i).Cells("img").Value = My.Resources.attention
Else
dg_data.Rows(i).Cells("img").Value = My.Resources.report_filed
End If
Next i
当然可以在之后使用丢弃第 11 列
dg_data.Columns(11).Visible = False
但我在这里寻找更优雅的解决方案,例如
Convert column 11 from to to img, replace "!" with image a, "c" with image "b" and so on.
对我有什么提示吗?提前致谢!
解决方案
推荐阅读
- json - 如何使用来自 json 的动态生成值在 Angular 4 中添加元标记
- reactjs - 使用 react-redux 连接打字稿
- python - 在 Windows 上安装 Cartopy 和依赖项
- java - Java 一个生产者和两个消费者
- gentics-mesh - 在项目之间共享节点
- python - 使用 Flask 提供 .mp4 文件并在 Objective-C 应用程序上播放会导致管道损坏且无法播放
- java - 从同一个 ANT 构建文件构建两个 jar 文件
- sql - 排序/排名 | 如果在子查询中?
- php - 试图理解 WordPress 主题 php
- android - Ionic3 Android 8.0 地理位置不起作用