Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Binding and object access

$
0
0

Hi,

I'm using EntityFramework for accessing data. My objects implement INotifyPropertyChanged. I put lists in BindingSources, and bind controls to those bindingsources. This all works nicely. However, I have some functional requirement that when a certain checkbox is being checked, a date field is set with a default value. I implement this by handling the CheckedChanged event. I retrieve the object via the BindingSource.Current property and set the date field. Setting the date field works great, but I lose the checkbox value then.

It took me a fair amount of time to narrow the problem down. I made a sample project which demonstrates the problem.

The MyDataObject has 2 properties, Message and MessageLength. When the TextChanged event of the textbox fires, I want to set the MessageLength to the .Length of the entered string. (Important: this could be implemented differently in this sample project, but that's not the point here!

What happens you edit the message (after each keystroke), is that the correct message length gets set into the object. This triggers a PropertyChanged event in the object, which the MessageLength textbox to refresh it's value, but somehow also the Message textbox.

How could I fix this, so I can set object properties like the way demonstrated?

I really don't want to resort to setting my bindings in code..

For the sample project, see https://github.com/mterwoord/WinFormsBindingProblem

Thanks!


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>