Databinding Enabled if false

I have a problem with data binding in a winforms application. In the following code, I have a binding to the included property of a text field. The allowed state depends on the value of the flag.

tbAmount.DataBindings.Add("Enabled", checkBox, "Checked", false, DataSourceUpdateMode.OnPropertyChanged); 

in this code, the text box is enabled if the check box is selected. but i need to flipped. I want the text box to be enabled if the box is unchecked. How can I achieve this?

+6
source share
1 answer

That should do it.

  Binding bind = new Binding("Enabled", checkBox, "Checked"); bind.Format += (sender, e) => e.Value = !((bool)e.Value); // invert the checked value textBox.DataBindings.Add(bind); 
+2
source

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


All Articles