If you are getting something like:

That's because you are getting what the ToString
function returns for an instance of a Bitmap
type to be displayed in a default DataGridViewTextBoxCell
. Note that, the Icon is not a part of your DataTable
, its just an image from your resources.
Instead, add a new DataGridViewImageColumn
after setting the DataSource
property of the DGV. Please consider the following example:
'Class level variables
Private bmp1 As New Bitmap(My.Resources.picture)
Private bmp2 As New Bitmap(My.Resources.picture1)
In a method that calls and displays the data replace this with your actual data source.
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("ID"))
dt.Columns.Add(New DataColumn("Item"))
dt.Columns.Add(New DataColumn("Status"))
For i As Integer = 1 To 10
dt.Rows.Add(i, $"Item {i}", $"Status {i}")
Next
With dgvInventory
.Clear()
.DataSource = Nothing
.DataSource = dt
.Columns("Item").HeaderText = "Item / Product / Service"
End With
Dim imageColIndex As Integer = dgvInventory.Columns.Count
Dim imgCol As New DataGridViewImageColumn(False) With {
.CellTemplate = New DataGridViewImageCell() With {
.Style = New DataGridViewCellStyle() With {
.Alignment = DataGridViewContentAlignment.MiddleCenter
}
},
.DisplayIndex = imageColIndex,
.Image = Nothing,
.Name = "Image",
.HeaderText = "Image",
.Width = CInt(dgvInventory.RowTemplate.Height * 1.5),
.DefaultCellStyle = New DataGridViewCellStyle() With {.NullValue = Nothing}
}
AddHandler dgvInventory.CellFormatting,
Sub(obj, arg)
If arg.ColumnIndex = imageColIndex Then
arg.Value = If(arg.RowIndex Mod 2 = 0, bmp1, bmp2)
End If
End Sub
dgvInventory.Columns.Insert(imageColIndex, imgCol)
Where imageColIndex
is the index of the image column.
Don't forget to clean up in the From.Closing event:
bmp1?.Dispose()
bmp2?.Dispose()
and you will get something like:

Note that, you don't need to add columns at design time, you can edit the columns properties after binding a DataTable
, DataView
, BindingSource
, ..etc. to your DGV.
Implementing that in your code:
tables.Clear()
con.Open()
sql = "SELECT ItemID, itemname, status, '' FROM [" & InventoryTable & "]"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, InventoryTable)
con.Close()
con.Dispose()
Dim view As New DataView(tables(0))
source1.DataSource = view
With dgvInventory
.Columns.Clear()
.DataSource = Nothing
.DataSource = view
.Columns(0).HeaderText = "ID"
.Columns(0).Width = 100
.Columns(1).HeaderText = "Item / Product / Service"
.Columns(1).Width = 300
.Columns(2).HeaderText = "Status"
.Columns(2).Width = 100
End With
Dim imageColIndex As Integer = dgvInventory.Columns.Count
Dim imgCol As New DataGridViewImageColumn(False) With {
.CellTemplate = New DataGridViewImageCell() With {
.Style = New DataGridViewCellStyle() With {
.Alignment = DataGridViewContentAlignment.MiddleCenter
}
},
.DisplayIndex = imageColIndex,
.Image = Nothing,
.Name = "Icon",
.HeaderText = "Icon",
.Width = CInt(dgvInventory.RowTemplate.Height * 1.5),
.DefaultCellStyle = New DataGridViewCellStyle() With {.NullValue = Nothing}
}
AddHandler dgvInventory.CellFormatting,
Sub(obj, arg)
If arg.ColumnIndex = imageColIndex Then
Dim status As Integer = Convert.ToInt32(
DirectCast(obj, DataGridView).Item(2, arg.RowIndex).Value)
arg.Value = If(status = 1, bmp1, bmp2)
End If
End Sub
dgvInventory.Columns.Insert(imageColIndex, imgCol)
dgvInventory.ClearSelection()