Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 545
dynamicuser Avatar asked Jun 17 '13 10:06

dynamicuser


1 Answers

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.

like image 125
King King Avatar answered Sep 30 '22 07:09

King King