0

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?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263

1 Answers1

0

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.

Community
  • 1
  • 1
daniele3004
  • 13,072
  • 12
  • 67
  • 75
  • I was looking into those events. However, CurrentChanged and CurrentItemChanged are raised for each property. – Ivan-Mark Debono Nov 10 '14 at 14:17
  • PositionChanged it's most interesting, and I use it often.This event is triggered when you move from one object to another of your BindingSource. – daniele3004 Nov 10 '14 at 14:23
  • Links are interesting. I would like to have something like bindingSource.HasChanged() which will tell me if the data in the bound controls changed or not. INotifyPropertyChanged wouldn't suite my needs in this case. – Ivan-Mark Debono Nov 10 '14 at 14:54
  • You can add your items to find out if a property has been changed, added or deleted. – daniele3004 Nov 10 '14 at 15:42