I VB.net, i have a datagridview, that shows some results of a database query. To generate it, i executed some sql query and wrote the data to a datatable. This table is then linked to the dgview
dg_data.DataSource = SqlData.DefaultView
Now one column can contain certain (fixed and predefined) characters describing a certain status of events that are handled with my app. I would like to replace these characters with more intuitive icons.
I managed to get that working but only in a new further column (12) containing an image according to another columns (11) code character. However, i want to REPLACE the column with that char and only show the image. This is what i have:
'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
One could of cource just discard column 11 afterwards using
dg_data.Columns(11).Visible = False
but i am looking for a more elegant solution here, e.g.
Convert column 11 from to to img, replace "!" with image a, "c" with image "b" and so on.
Any hints for me? Thanks in advance!