CheckBox.DataBindings.Add not working

I am trying to link a flag contained in a winforms data repeater, however the flag by itself does not tick. When linked to a shortcut, it works

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

Check box (does not work) -

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

Any ideas why this is not working?

thanks

+4
source share
2 answers

If it's a bit (0 or 1), you need to add a Format event handler for 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 simple task when you are working with Binding .

+5
source

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

0
source

Source: https://habr.com/ru/post/1486593/


All Articles