Syntax question for checkboxes

Roman_Candle

Member
Joined
Jan 19, 2005
Messages
10
Programming Experience
Beginner
i am looking to return data from an access database.
for a normal textbox i use the code

Me.txtName.Text = reader.GetString(1)
which works just fine.

but i was wondering how to return the value of a checkbox from the DB.
ie is something like
Me.ckbYes.Checked = reader.GetBoolean(2)

or could be how i set it up in the DB.
Currently i declare it in the DB as a yes/no field and then set it to true/false in the format field.

thanks
 
checkbox stuff

Set the databindings of the checkbox to the dataset field. There are two bindings here "checked" and "text".
the code generated looks like this:

Me.editTest.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Me.DatasetName1, "FieldName"))
Me.editTest.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DatasetName1, "FieldName"))

A simple Sub will change the text when it is clicked on and off:

Private Sub editTestChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles editTest.CheckedChanged

If editTest.Checked = True Then
editTest.Text = "True"
editTest.ForeColor = System.Drawing.Color.Green
Else
editTest.Text = "False"
editTest.ForeColor = System.Drawing.Color.Red
End If

End Sub
 
Back
Top