miguelmpn
miguelmpn

Reputation: 2017

One-way binding

I know this question exists but I can't find the solution in the answers.

I have a form with a data-binding to a custom class so that when changing the form, the custom class gets notified (the inverse will never happen).

myForm.DataBindings.Add("Items", ItemsController.Singleton, "Items", false, 
                        DataSourceUpdateMode.OnPropertyChanged);

What is happening now is that when I create an instance of the form and set the Items property with some values, the data-binding checks for the ItemsController Items property and updates it back to the form with 0 Items, I want to prevent that using a one-way data-binding.

Is it possible or I will have to rely on event's only?

Upvotes: 2

Views: 3156

Answers (1)

Ivan Stoev
Ivan Stoev

Reputation: 205619

Looks like you are seeking for Binding.ControlUpdateMode property:

Gets or sets when changes to the data source are propagated to the bound control property

myForm.DataBindings.Add(new Binding("Items", ItemsController.Singleton, "Items")
{
    DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged,
    ControlUpdateMode = ControlUpdateMode.Never
});

Upvotes: 6

Related Questions