简体   繁体   中英

How do I refresh Controls bound to a DataSource in C# User Control

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,

Description

You must implement the INotifyPropertyChanged interface.

The INotifyPropertyChanged interface is used to notify clients, typically binding clients, that a property value has changed.

Sample

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");
            }
        }
    }
}

More Information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM