Reputation: 4519
I am slightly confused in my understanding of DataSources in Winforms, and was hoping somebody might be able to clear something up for me.
I have one control, lets call it Host, and I have another one, called Client.
"Host" contains multiple instances of "Client"
Client displays four main variables, in labels at the moment, which are bound to a BindingSource per control.
I am updating these BindingSources from the Host control however, using database values retrieved using LINQ.
When I update the BindingSource from the "Host" control, the values to not update in the "Client" controls as I expected they would.
Can anyone give me a quick explanation of any methods I need to call in order to make sure that the labels refresh with latest data whenever the BindingSource is changed?
Regards,
Upvotes: 0
Views: 1495
Reputation: 60448
You must implement the INotifyPropertyChanged
interface.
The INotifyPropertyChanged interface is used to notify clients, typically binding clients, that a property value has changed.
public class MyClass : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
private string myProperty;
public string MyProperty
{
get
{
return this.myProperty;
}
set
{
if (value != this.myProperty)
{
this.myProperty = value;
NotifyPropertyChanged("MyProperty");
}
}
}
}
Upvotes: 1