I have added a datagridview (DGV) to a windows form. I programmatically bind it to a data source. I added a few DataGridViewCheckBoxColumn
columns. I loop through the columns of the DGV until I get to one of the checkbox columns. I then loop through all rows. For each Row / Column pair I query a database table using Row and Column information and retrieve a Boolean value. I set the checkbox cell value to the Boolean value. When the code finishes and the DGV is revealed, the bound cells are fine but no matter what I set the checkbox cells to (Boolean from datatable info, or 1, or TRUE) it always shows as an unchecked checkbox.
DGV.Columns.Add(CreateChec
kBoxColumn
(sNewColum
nName, sHeaderText))
Private Function CreateCheckBoxColumn(ByVal
sNewColumnName, ByVal HeaderText) As DataGridViewCheckBoxColumn
Dim dataGridViewCheckBoxColumn
1 As New DataGridViewCheckBoxColumn
()
dataGridViewCheckBoxColumn
1.HeaderTe
xt = sHeaderText
dataGridViewCheckBoxColumn
1.Name = sNewColumnName
dataGridViewCheckBoxColumn
1.ThreeSta
te = False
dataGridViewCheckBoxColumn
1.ValueTyp
e = GetType(Boolean)
Return dataGridViewCheckBoxColumn
1
End Function
For Each oColumn In Me.DGV.Columns
If InStr(1, oColumn.Name, "res_", CompareMethod.Text) > 0 Then
sHeaderText = oColumn.HeaderText
For iLoop = 0 To Me.DGV.Rows.Count - 1
sNameAddress = Me.DGV.Item("Fam_nameaddre
ss", iLoop).Value
bDBase_Value = Me.Tbl_FamilyTableAdapter.
IsMemberRe
sourceAvai
lable(sNam
eAddress, sHeaderText)
Me.DGV.Item(oColumn.Index,
iLoop).Value = bDBase_Value
Next
End If
Next
Start Free Trial