Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > "Who" handles PropertyChanged event?
 

"Who" handles PropertyChanged event?

"Who" handlesPropertyChangedevent? CurrencyManager of acorrespondingForm or each CurrencyManager inside an ApplicationDomain?
RobbKirk  Monday, July 27, 2009 8:48 AM

When you add bindingsource, .net framework will automatically register the ChangeEvent for the databinding.

Use Reflector you will see BindingsCollection.Add(Binding) method:

protected internal void Add(Binding binding)

{

CollectionChangeEventArgs e = new CollectionChangeEventArgs(CollectionChangeAction.Add, binding);

this.OnCollectionChanging(e);

this.AddCore(binding);

this.OnCollectionChanged(e);

}

Then the CurrencyManager will manage the datasource.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, August 03, 2009 12:38 PM
Not sure I fully understand the question. Can you be more specific in what you are trying to accomplish?
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Monday, July 27, 2009 4:00 PM
Hi Deborah,

Ok, please, have a look at the code below:

    public class MyDataSet : INotifyPropertyChanged
    {
        private string _prop;
        public string MyProp
        {
            get { return _prop; }
            set
            {
                _prop = value;
                NotifyPropertyChanged("MyProp");
            }
        }
        public MyDataSet(string prop)
        {
            MyProp = prop;
        }
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }

When PropertyChanged(this, new PropertyChangedEventArgs(info)); is executed, "who" handles that event?
I have one FormA, where a textbox bound to a dataset (class in my case), the event fired by
PropertyChanged is posted to the CurrencyManager(CM) of the FormA or to every CMs of each form inside
myapplication/application domain?

RobbKirk  Monday, July 27, 2009 8:23 PM
It would assume it would raise the event to any Binding Source bound to MyDataSet.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Monday, July 27, 2009 8:29 PM
It would assume it would raise the event to any Binding Source bound to MyDataSet.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
Stop, MyDataSet is the Binding Source, isn't it?

The event is fired inside an instance of MyDataSet and then comes to FormA's CurrencyManager or to each CM, and then CMs compare the pointer to DataSource (MyDataSet) and decide whom it has been posted to?
RobbKirk  Monday, July 27, 2009 8:49 PM
Not sure if we are talking about the same thing ... but I was referring to this:

System.Windows.Forms.BindingSource

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.aspx

(Big "B" BindingSource not Little "b" binding source).

It is what I use as the wrapper for the CurrencyManager.

So I assume you are not using the BindingSource object?

I have a sample CRUD application that uses the BindingSource here, if you are interested:

http://www.insteptech.com/techLibrary/samplecode.htm
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Monday, July 27, 2009 8:58 PM
Thanks for your assistance.

(From my vision)
Yes, I'm using BindingSource. When you use Add method, you add an object, which is the source itself, it contains properties populated with data.
Then the BindingSource is the component responsible to manage data flow between the form and the data source, such as updatethe data source(an instance of MyDataSet class in my case)withdata entered inside the form, that is why it is called Currency Manager.
Data is changed in two directions: from form to data source and from data source to form, when I change a property value.

The direction from form to data source is managed by BindingSource, but from data source to form by using INotifyPropertyChanged, which is implemented byNotifyPropertyChangedmethod.
The method fires PropertyChanged(this, new PropertyChangedEventArgs(info)); event.
That event comes to BindingSource Currency Manager (CM handles it)...

So, my question is:
The event is fired inside an instance of MyDataSet and then comes to FormA's CurrencyManager or to each CM, and then CMs compare the pointer to DataSource (MyDataSet) and decide whom it has been posted to?
RobbKirk  Monday, July 27, 2009 9:54 PM

Hi,

INotifyPropertyChanged interface is used to raise an event that the data source has changed.

Windows Forms data binding is driven off of change notification. This means that windows form will not update a user interface element (Control) unless that data source notifies the windows form data binding runtime that the data has changed (By providing a notification event). That is why we use INotifyPropertyChanged interface or PropertyEvnet with the customized datasource.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, August 03, 2009 5:05 AM

"Who" handles PropertyChanged event?

  • Edited byRobbKirk Monday, August 03, 2009 5:42 AM
  •  
RobbKirk  Monday, August 03, 2009 5:39 AM

When you add bindingsource, .net framework will automatically register the ChangeEvent for the databinding.

Use Reflector you will see BindingsCollection.Add(Binding) method:

protected internal void Add(Binding binding)

{

CollectionChangeEventArgs e = new CollectionChangeEventArgs(CollectionChangeAction.Add, binding);

this.OnCollectionChanging(e);

this.AddCore(binding);

this.OnCollectionChanged(e);

}

Then the CurrencyManager will manage the datasource.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, August 03, 2009 12:38 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView Events Between Forms
• DataGridViewComboBoxCell Refresh?
• What can I use instead of 'DataGridView.Loaded event'?
• DataGridViewComboBoxColum on selectedIndexChanged
• Binding Textbox to String
• Databindings Advanced Properties Design Window bug.
• row filter in data grid view
• Datagrid to Excel
• How Do I Format a DataGridView Column to datagridviewcheckbox Type.?
• How should I load this datarow?