DataSet Bound Checkbox Value


I have bound a checkbox to a dataset using
cbSettings.DataBindings.Add("CheckState", BindingSource1, "Settings", True, DataSourceUpdateMode.OnValidation, False)

Open in new window

However, if the checkbox is unchecked then the dataset value is set to NULL whereas it should be 0 (database column is BIT)

The ThreeState property of the checkbox is False

Thanks, Greg
Who is Participating?
spen_langConnect With a Mentor Author Commented:
OK, I used the following code in the end to add a new record:

    Private Sub btnAddNew_Click(sender As System.Object, e As System.EventArgs) Handles btnAddNew.Click

        Dim drvUsers As DataRowView

        drvUsers = Me.BindingSource1.AddNew()
        cbActive.Checked = True
        cbEmployeeAccidentRate.Checked = False
        cbInvoiceAccuracy.Checked = False
        cbCreateEditUsers.Checked = False
        cbSettings.Checked = False
        txtWindowsUsername.Text = "(NEW)"
        txtName.Text = ""

        drvUsers.Row.Item("UserID") = txtWindowsUsername.Text
        drvUsers.Row.Item("Username") = txtName.Text
        drvUsers.Row.Item("InvoiceAccuracy") = cbInvoiceAccuracy.Checked
        drvUsers.Row.Item("EmployeeAccidentRate") = cbEmployeeAccidentRate.Checked
        drvUsers.Row.Item("Settings") = cbSettings.Checked
        drvUsers.Row.Item("Users") = cbCreateEditUsers.Checked
        drvUsers.Row.Item("Active") = cbActive.Checked


    End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.