Hi
Difficult to understand what you are asking for. I think you need to have the checkbox auto check / uncheck depending on some other column - moybe!
Anyway, here is some code that may help. This example explicitly loads the datatable but yours takes from a database - the ideas are the same.
What I do here: set up the datatable with some columns, add some random data just for the example. Then, run through a loop to set the additional boolean column values according to the rules I have used (column [Two] empty = False, column [Two] not empty = True)
After that, changing the value of a cell in column [Two] will auto check / uncheck the first (checkboxcolomn) column.
Option Strict On
Option Explicit On
Public Class Form1
Dim dt As New DataTable("Freddy")
Dim r As New Random
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With dt
.Columns.Add("One", GetType(Integer))
.Columns.Add("Two", GetType(String))
.Columns.Add("Three", GetType(Double))
For i As Integer = 0 To 99
.Rows.Add(r.Next(9, 99), IIf(r.Next(0, 2) = 1, "Freddy", String.Empty), r.NextDouble() * 99)
Next
End With
DataGridView1.DataSource = dt
Dim checkboxcolumn As New DataGridViewCheckBoxColumn()
With checkboxcolumn
.HeaderText = "*"
.Width = 20
.Name = "checkboxcolomn"
End With
DataGridView1.Columns.Insert(0, checkboxcolumn)
For index As Integer = 0 To DataGridView1.Rows.Count - 1
If Not index = DataGridView1.NewRowIndex Then
DataGridView1("checkboxcolomn", index).Value = Not DataGridView1("Two", index).Value.ToString = String.Empty
End If
Next
End Sub
Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
DataGridView1("checkboxcolomn", e.RowIndex).Value = Not DataGridView1("Two", e.RowIndex).Value.ToString = String.Empty
End Sub
End Class