We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

How to Bind a checkbox to a binding source object

CraigLazar
CraigLazar asked
on
Medium Priority
1,633 Views
Last Modified: 2012-05-06
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
Comment
Watch Question

CERTIFIED EXPERT
Commented:
The code above is in the designer.vb or in your own code?

Dabas

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
move the code of binding to the checkbox to the bottom and keep other bindings on the top.

Author

Commented:
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
CERTIFIED EXPERT

Commented:
Have you tried without the .Clear() line?

Author

Commented:
to Dabas:
yes i tried that and still same problem
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
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.

Author

Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.