0
votes

I have a DTO class, and in my WinForms client I'm creating a datasource for it. In form design, I bind the bindingsource to this datasource so that all controls will be bound automatically.

In code I do the following to bind the bindingsource to an empty object:

public void Clear()
{
    var dto = new MyDTO();
    bindingSource.DataSource = dto;
}

To get an item from the db and display it is similar:

public void Load(int id)
{
    var dto = dtoRequest.Get(id);
    bindingSource.DataSource = dto;
}

However I want to know if data has changed after the datasource has been set. Do I need to implement INotifyPropertyChanged in my DTO classes? Because if this is the case, it would defeat the purpose of having DTO's in the first place.

Are there any other solutions?

1

1 Answers

0
votes

I develop just like you, using DTO to the side VIEW. I never used INotifyPropertyChanged. If you want to know when the data has changed you have to use just the events of the BindingSource or build properties in your DTO.

enter image description here

In addition see my answer to this post

How to set values in cells of row in DatagridView when I change field value?

and this famous question

Implementing INotifyPropertyChanged - does a better way exist?

I hope I've given you directions. If you have any questions please ask me here.

Remember that a lot depends on us how we structure our "framework" for development.

With this strategy I've ever completed all my work, that does not mean it's a bad idea to use INotifyPropertyChanged.