This question is locked. New answers and comments are not allowed.
Hi,
I have two objects "Invoice" and "Details". The Invoice class holds a field of ObservableCollection<Details> and therefore has a Property called "InvoiceDetails". In Invoice I create the ObservableCollection-Object and add an eventhandler to the CollectionChanged event.
I now load a previously saved instance from Invoice and add a new Detail to the Collection. All went fine, but the event does not fire.
I tried the same with a BindingList and it's the same behaviour: no event fires.
Example (in VB):
public class Invoice
Dim _details as ObservableCollection(Of Details) = new ObservableCollection(Of Details)()
public sub New()
AddHandler _details.CollectionChanged, AddressOf details_CollectionChanged
end sub
public property InvoiceDetails() as ObservableCollection(Of Details)
get
return _details
end get
end property
private sub details_CollectionChanged(sender as Object, e as EventArgs)
MessageBox.Show("Detail added")
end sub
end class
and in a form I call:
dim result as Invoice = (From i in scope.Extent(of Invoice)() Where i.Id = 1 Select i).First()
result.Add(new Detail())
My tasks to solve are:
- I have an object and need to know every change of all sub- und listed objects in this instance. They all implement INotifyPropertyChanged for tracking the changed object and property
- I have a collection to which an instance is added, removed or changed. I now have to recalculate totals and subtotals in the "master" object
- Tracking changes of Collections while this collection is databound to e.g. an UltraWinGrid
Thanks,
Daniel Schilling
Edit: Typo
I have two objects "Invoice" and "Details". The Invoice class holds a field of ObservableCollection<Details> and therefore has a Property called "InvoiceDetails". In Invoice I create the ObservableCollection-Object and add an eventhandler to the CollectionChanged event.
I now load a previously saved instance from Invoice and add a new Detail to the Collection. All went fine, but the event does not fire.
I tried the same with a BindingList and it's the same behaviour: no event fires.
Example (in VB):
public class Invoice
Dim _details as ObservableCollection(Of Details) = new ObservableCollection(Of Details)()
public sub New()
AddHandler _details.CollectionChanged, AddressOf details_CollectionChanged
end sub
public property InvoiceDetails() as ObservableCollection(Of Details)
get
return _details
end get
end property
private sub details_CollectionChanged(sender as Object, e as EventArgs)
MessageBox.Show("Detail added")
end sub
end class
and in a form I call:
dim result as Invoice = (From i in scope.Extent(of Invoice)() Where i.Id = 1 Select i).First()
result.Add(new Detail())
My tasks to solve are:
- I have an object and need to know every change of all sub- und listed objects in this instance. They all implement INotifyPropertyChanged for tracking the changed object and property
- I have a collection to which an instance is added, removed or changed. I now have to recalculate totals and subtotals in the "master" object
- Tracking changes of Collections while this collection is databound to e.g. an UltraWinGrid
Thanks,
Daniel Schilling
Edit: Typo