I guess I can identify a couple of problems with the code. My version
would be:

---
For Each objChk in GroupBox2.Controls
  If TypeOf objChk is CheckBox Then
    Dim chk as CheckBox = DirectCast(objChk, CheckBox)
    If chk.Checked = True Then
      objCurrentRow1.Item("Present") = True
    End If
  End If
Next
---

The differences are:
1. You aren't storing the casted CheckBox into anything.
2. You aren't setting the value of the column "Present" to a boolean,
rather you are setting to the object of the CheckBox itself.


On Feb 4, 10:16 pm, Laura <[email protected]> wrote:
> Hi,
> I'm trying to loop through some checkboxes and save the values to a
> row in the database (as below)
>
> Dim objChk As Object
> Dim Checked As Boolean = False
>        For Each objChk In GroupBox2.Controls
>                   If TypeOf objChk Is CheckBox AndAlso DirectCast
> (objChk, CheckBox).Checked Then
>                         objCurrentRow1.Item("Present") = objChk
>                     End If
>         Next
>
> I've ran the project with breakpoints around this mark and it appears
> to loop through 3/4 times and then I get the following error:
>
> "Unable to cast object of type 'System.Windows.Forms.CheckBox' to type
> 'System.IConvertible'.Couldn't store <System.Windows.Forms.CheckBox,
> CheckState: 1> in Present Column.  Expected type is Boolean."
>
> Can you identify any simple thing wrong with the above code that would
> rectify this error??

Reply via email to