This sample demonstrates the implementation of a custom collection.
Features:
The custom collection is implemented in the class Customer.
It consists of the following four classes:
PopulateCustomer
Customer
CustomerCollection
CustomerCollectionEnumerator
The PopulateCustomer class calls the CreateCustomer() method which in turn calls the ReadCustomer() method to populate values.
An object for the CustomerCollection class is created and the objects of the Customer class are added.
New customer objects are added as children to the cust1 object.
Customer class implements from the IEditableObject interface.
It has the PropertyChanged event, which is associated with the RaisePropertyChanged() method.
CustomerCollection class implements from the IList and the IBindingList interfaces.
CustomerCollectionEnumerator class implements from the IEnumerator interface.
An object for the CustomerCollection class is created and the objects of the Customer class are added using the following code:
CustomerCollection customers = new CustomerCollection(); Customer cust1 = ReadCustomer1(); customers.Add(cust1);
New customer objects are added as children to the cust1 object using the following code:
cust1.Children.Add(ReadCustomer3()); cust1.Children.Add(ReadCustomer4());
The Customer class implements from the IEditableObject interface.
It has the following fields:
private CustomerCollection _parentCollection; private CustomerCollection _children = new CustomerCollection(); private CustomerData custData; private CustomerData backupData; private bool beginEditCalled = false; private bool modified = false; private IEditableObject _forwardEditableObject;
It has the PropertyChanged event, which is associated with the RaisePropertyChanged() method.