dynamicuser
dynamicuser

Reputation: 1552

CheckBox.DataBindings.Add not working

I am trying to bind a checkbox contained within a winforms data repeater, however the checkbox itself it not ticking. When binding to a label it works

lbSchoolFri.DataBindings.Add("Text", bindingSource5, "SchoolName");

Checkbox (not working) -

cbSchoolFri.DataBindings.Add("Checked", bindingSource5, "SchoolContacted");

Any ideas why this is not working?

Thanks

Upvotes: 5

Views: 6693

Answers (2)

MQuiggGeorgia
MQuiggGeorgia

Reputation: 769

Another possibility: You need to add "true" as a parameter to Binding; see here... look at the bottom of the "UPDATE Aug 18" code sample.

Upvotes: 0

King King
King King

Reputation: 63367

If it is a bit (0 or 1), you have to add Format event handler for your Binding:

Binding bind = new Binding("Checked", bindingSource5, "SchoolContacted");
bind.Format += (s,e) => {
   e.Value = (int)e.Value == 1;
};
cbSchoolFri.DataBindings.Add(bind);

This is a very basic task when you work with Binding.

Upvotes: 6

Related Questions