BindingList <T> implementation

I am trying to learn more about BindingList because I believe that this will help me with the project I'm working on.

Currently, I have a class of objects (ScannedImage), which is a subtype of the class (HashedImage), which is subtypes of my own .NET object (image). There is no reason why I could not move the two subtypes together. I am just subtypes of the object that I previously built, but now I will store my ScannedImage object in RDB (well, not technically - only the details and, possibly, the thumbnail).

In addition, the object class has member types that are my own custom types (Keywords). I use a custom datagridview to represent these objects, but I process all changes to the ScannedImage object using my own code. As you can imagine, I have quite a few processing events that occur in these basic types.

So, if I changed my object to an INotifyPropertyChanged implementation, will the collection of objects (BindingList implementation) receive notifications of changes to the ScannedImage object?

Also, if the keywords were to implement INotifyPropertyChanged, were the changes available for the BindingList through the ScannedImage object?

Sorry if this seems like a pretty newbie. I only recently discovered a BindingList and had no formal training in C # programming - it's hard for me to move forward with this.

Also, if anyone has some good reference material, I would be grateful for the links. Obviously, I looked at the MSDN library. I found some good links on the Internet, but it seems that many people now use WPF and ObservableCollection.

My project is based on Winforms and the .Net3.5 framework.

TIA

+3
source share
1 answer

I will answer both of your questions:

[I] f INotifyPropertyChanged, ( BindingList) ScannedImage?

BindingList<T> System.ComponentModel, , INotifyPropertyChanged. .

, " BindingList", . . IBindingList, , , , , , , .

, IBindingList; BindingList<T>, , .

, INotifyPropertyChanged, BindingList ScannedImage?

, . BindingList<T> , ( , ).

, , ScannedImage, Keywords, PropertyChanged .

:

public class ScannedImage : INotifyPropertyChanged
{
    private Keywords keywords;

    protected void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            PropertyChangedEventArgs e = new 
                PropertyChangedEventArgs(propertyName);
            handler(this, e);
        }
    }

    private void KeywordsChanged(object sender, PropertyChangedEventArgs e)
    {
        OnPropertyChanged("Keywords");
    }

    private void SetKeywords(Keywords newKeywords)
    {
        Keywords oldKeywords = this.keywords;
        this.keywords = null;
        if (oldKeywords != null)
            oldKeywords.PropertyChanged -= KeywordsChanged;
        this.keywords = newKeywords;
        if (newKeywords != null)
            newKeywords.PropertyChanged += KeywordsChanged;
    }

    public Keywords Keywords
    {
        get { return keywords; }
        set { SetKeywords(value); }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

public class Keywords : INotfifyPropertyChanged { ... }

, , . ScannedImage PropertyChanged Keywords , , Keywords . , .

+1

Source: https://habr.com/ru/post/1744702/


All Articles