How to add different colour icons/images automatic to the Row Header of a DataGridView based on database fill the DataTable VB.NET?

here I failed to apply the column "ColorIndex"

maybe something is wrong in the code implementation from me .

Full code is at the link below and according to the first answer option

Here's a link!

Thanks

 Public Sub jokenselect(ByVal sql As String)
        Try
            con.Open()
            With cmd
                .Connection = con
                .CommandText = sql
            End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        End Try
        con.Close()
        da.Dispose()
    End Sub
    Public Sub filltable(ByVal dtgrd As Object, ByVal design As String)

        Try
            da.SelectCommand = cmd
            da.Fill(publictable)
            dtgrd.DataSource = publictable
            Select Case design
                Case "Temp"
            End Select
            da.Dispose()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information)
        End Try
    End Sub

    Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        colors = GetType(Color).
            GetProperties(BindingFlags.Public Or BindingFlags.Static).
            Where(Function(pi) pi.PropertyType = GetType(Color)).
            Select(Function(pi) CType(pi.GetValue(GetType(Color), Nothing), Color)).
            Where(Function(c)
                      Return ((
                  c.R * 0.299F +
                  c.G * 0.587F +
                  c.B * 0.114F) / 256.0F) <= 0.5F
                  End Function).ToArray()
        bmp = My.Resources.money
        Dim Table1 = New DataTable("TableName")
        Table1.Columns.Add("ColorIndex", GetType(Integer))
        Dim dt = Table1.DefaultView.
    ToTable(False, Table1.Columns.
    Cast(Of DataColumn).
    Where(Function(c) c.ColumnName <> "ColorIndex").
    Select(Function(c) c.ColumnName).ToArray())
        da.Update(dt)
        DataGridView1.GetType().
    GetProperty("DoubleBuffered",
                BindingFlags.Instance Or BindingFlags.NonPublic).
    SetValue(DataGridView1, True)
        'DataGridView1.DataSource = Table1
        DataGridView1.Columns("ColorIndex").Visible = False
        jokenselect("Select * From tblPayrollDecision")
        filltable(DataGridView1, "Temp")
        UpdateColorColumn()
        Table1.AcceptChanges()
    End Sub

Object Reference not set to an instance of an object

0

There are 0 best solutions below