I have a DataGridView and a BindingSource bs populated using bs.DataSource = list; where list is a BindingList<Item>.
All I want is to have each changed Item notified that it is changed, and each deleted item notified that it is deleted. Or instead, I would like to have access to changed, new and deleted items after user edits the grid and presses the button.
Edit:
public abstract class Item : INotifyPropertyChanged { .......
public Item()
{
Id = IdCounter++;
Pairs = new HashSet<int>();
State = ItemState.NEW;
Name = "#noname";
Note = "";
PropertyChanged += new PropertyChangedEventHandler(Item_PropertyChanged);
}
void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
SetChanged();
}
/* nastaví příznak, že se něco změnilo - to následně vyvolá UPDATE (při použití SQL úložiště) */
public void SetChanged()
{
State = ItemState.CHANGED;
}
Youll want to listen for the
ListChangedevent on yourBindingList<Item>orBindingSource bs. In theListChangedEventArgs, theListChangedTypewith have specific details about what changed:I bolded the ones you mentioned.
Update
Ok, so this is what the
Itemclass should look like:Then when you attach to you BindingList you should get the updates. Then you can change the state of your item when you receive those events or through databinding.