Link to home
Start Free TrialLog in
Avatar of CraigLazar
CraigLazar

asked on

How to Bind a checkbox to a binding source object

Hi,
I am using VB.net 2008 and i am having trouble binding to a checkbox on my form.
this is my code
           'chkLevyCharge.Checked = False
            'chkLevyCharge.DataBindings.Clear()
            'chkLevyCharge.DataBindings.Add("Checked", bs, "LevyCharge")
it binds to it and when i scroll through the bs object it works, however the problem is when i try and add a new record to the bs (dataset)
bs.addNew() it does not clear the rest of my text boxes which i have bound to the bs, when i comment out the section of code binding to the checkbox then the bs.addnew() method works

thanks
ASKER CERTIFIED SOLUTION
Avatar of Dabas
Dabas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CraigLazar
CraigLazar

ASKER

hi the code is not in the vb designer.

to code cruiser
i have bound text fields as well and i am using the same method
            txtAmount.Text = ""
            txtAmount.DataBindings.Clear()
            txtAmount.DataBindings.Add("Text", bs, "Amount")

my code to bind to the checkbox is at the bottom
Have you tried without the .Clear() line?
to Dabas:
yes i tried that and still same problem
Set a default value for the checkbox column in the dataset. I think the problem is that the field to which the checkbox is bound contains DBNull when a new record is inserted which may be causing problems.
Hi,
i still battled to get it working, so i landed up using a hidden text box to store the value then i got it working
thanks for the help anyway