Hum, ok, assume a list box list like this:
Then code to fill above like this:
Sub LoadData()
Using conn As New SqlConnection(My.Settings.TEST4)
Using cmdSQL As New SqlCommand("SELECT GID, GName, GCnt from Products ORDER BY GName", conn)
conn.Open()
Dim rst As New DataTable
rst.Load(cmdSQL.ExecuteReader)
ListBox1.DataSource = rst
ListBox1.DataBind()
Dim iRow = 0
For Each lRow As ListItem In ListBox1.Items
Dim sHex As String = Hex(rst.Rows(iRow).Item("GCnt")).PadLeft(6, "0")
lRow.Attributes.Add("style", "background-color:#" & sHex)
iRow += 1
Next
End Using
End Using
End Sub
and the output is this:
And our data table was this:
Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta Canada