5

I've seen that WPF has a UpdateSourceTrigger property that will allow for data binding to take place after a control has lost focus, is there something similar for winforms?

I've come across an issue where when updating a databound value, the entire source is changed rather than the single property.

This is causing me a problem as I have a CheckBox that when changed checked state, updates another source that has a databinding from the same databinding source, which makes my checkbox never change value (or rather it does then changes it back)

I've created an example program that demonstrates this. (Basic form with a checkbox and text box)

Alternatively, is there another way to handle my databinding to make only the data bound property value change instead of the source?

Sayse
  • 42,633
  • 14
  • 77
  • 146
  • I don't understand well what you want. The databinding should bind the data between the Control and the Source. You want to change some value in the Control without changing the Source? Some concrete example would be nice. – King King Jun 07 '13 at 10:14
  • @King King, the link provides a full example. In the example, on line 8, you can see it calls "Text"(Text is overridden) which ultimately changes the databound value of the textbox which as a result then resets the checkbox to the sources value and thus never allows the checkbox to have a different value – Sayse Jun 07 '13 at 10:23
  • @sayse winforms' databinding is laughable compared to WPF. I don't think you will be able to achieve this without resorting to subclassing the textbox or stuff like that. – Federico Berasategui Jun 07 '13 at 22:37
  • @highcore - I was afraid of that.. I was thinking I would need to move my checkbox binding source elsewhere.. – Sayse Jun 08 '13 at 08:23
  • See http://stackoverflow.com/a/4724828/194717 and http://stackoverflow.com/a/17458095/194717 – Tony Apr 22 '17 at 15:50

1 Answers1

1

In the end I had to manually update the databinding withith the CheckedChanged event.

For example, using the source for my example program.

checkBox1.CheckedChanged += (s, e) => { 
  dc.BooleanVal = ((CheckBox)s).checked;
  customControl1.Text = "3"; 
  label1.Text = dc.BooleanVal.ToString(); };
Sayse
  • 42,633
  • 14
  • 77
  • 146