Click here to Skip to main content
Click here to Skip to main content

Implementing a strongly typed collection with sort/filter/GetChanges features

, 6 Jul 2005
Rate this:
Please Sign up or sign in to vote.
A strongly typed collection that implements CollectionBase and IBindingList interfaces with interesting features (sort, filter, getchanges).


In my first steps with .NET, I was impressed by the dataset features. Data access was very simple to use/ to bind on Windows forms components such as DataGrid or ComboBox. But with datasets we are far from OOP. We are always working with Tables (DataTable), rows and columns. So when I began to create my own business objects, all became so difficult: data access problems, binding problems and collection problems. I needed a collection of each business objects that presents the DataSet/DataView features (Sorting, Filtering and the DataSet's GetChanges feature) and it must not be a dataset.

I found many discussion about Collection / Strongly Typed Collections but no one presents all features I needed. So I decided to develop my own custom collection that implements the needed interfaces and functions to be simple to use with Windows forms and also in data access.


  • DataBinding

    The custom collection inherits from CollectionBase abstract class and implements IBindingList interface and can be bound on all controls of Windows forms (datagrid, combo, list,...).

  • Sorting

    The sorting feature is implemented in the IBindingList Interface. So you can sort a column in a DataGrid by clicking on the header of the column.

    Sorting is accessible with a Sort method that accepts a string as parameter ( like the property of the DataView).

  • Filtering

    Dataview presents an very useful feature specially when bound to a DataGrid: Filtering. The custom collection offers too the same feature via the ItemFilter property (RowFilter in the DataView). You can set to the ItemFilter property a string like "Name = Test" or "BirthDate > 01/01/1980" and the collection is updated to display only items that respond to the criteria.

  • GetChanges feature

    The custom collection is based on an abstract object called BaseObject which have a property called ObjectState that can be UnChanged, Added, Deleted or Changed. So any action you do on the collection is stored and you can have the 'List of Changes" made by the user on the collection of items.

    So any business object you need to implement in a collection must inherit from BaseObject.


To create your own custom collection, you need a business object that inherits from BaseObject class. For example, if you create a customer class which present a Name property, this code is needed :

public class Customer : BaseObject
    public Customer()
        // TODO: Add constructor logic here
    private string TmpName;
    public string Name
        get{return TmpName;}
            if (base.Compare(TmpName, value) !=0)
                TmpName = value;
                SetDirtyFlag(); // To set the isdirty property of the object to true


Then create the Customers class which inherit from abstract class CustomCollection. Code will be like this:

public class Customers: CustomCollection
   public Customers()
       // define the type of the collection items to Customer
       this.ItemType = typeof(Customer); 
   //indexer that overides the default indexer
   public new Customer this[int index]
         return (Customer)(base[index]);
         base[index] = value;
// GetChanges Method that overrides the default one 
//to have a Customer Collection in return
    public new Customers GetChanges()
        return (Customers) base.GetChanges();

The demo project includes also source code of CustomCollection and BaseObject.


With this CustomCollection, no need to work with DataSets and DataViews. It combines the features of both of these components and we can work with our business objects. So data access can be easier, databinding in Windows forms and web forms is assured and performance is much better than dataset when filling the custom collection from a datareader.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Hayder Marzouk
Web Developer
France France
MCSD Asp.Net certified developer

Comments and Discussions

QuestionFind? Pinmemberble0t26-Oct-06 7:28 version? Pinmembercxjc23-Aug-06 6:38 
QuestionNot Case sensative? PinmemberBigJoe7141-Jun-06 15:16 
GeneralVB.Net Version Pinmembersrinum28-Feb-06 6:32 
QuestionWhat about design-time support for data binding PinmemberAlisterTheDog14-Jan-06 9:55 
QuestionSerialization? Pinmemberbelchski14-Nov-05 10:22 
AnswerRe: Serialization? PinmemberAshwin Seshadri14-Nov-05 14:06 
GeneralRe: Serialization? Pinmemberbelchski14-Nov-05 14:20 
GeneralRe: Serialization? PinmemberJohny Nguyen23-Nov-05 17:23 
GeneralRe: Serialization? PinmemberPatrick Hatton21-Dec-05 7:00 
GeneralRe: Serialization? Pinmembersrinum23-Feb-06 10:02 
GeneralRe: Serialization? Pinmembersrinum23-Feb-06 11:37 
GeneralRe: Serialization? PinmemberAtlas200228-Feb-06 5:01 
GeneralI greatly increased performance!!!! PinmemberAlexei Tarnakin18-Oct-05 1:47 
GeneralRe: I greatly increased performance!!!! PinsussAnonymous18-Oct-05 2:55 
GeneralRe: I greatly increased performance!!!! PinmemberAlexei Tarnakin18-Oct-05 6:28 
GeneralProblem with clear method PinmemberAlexei Tarnakin28-Sep-05 23:01 
GeneralRe: Problem with clear method PinmemberJohny Nguyen18-Oct-05 0:49 
GeneralRe: Problem with clear method PinmemberAlexei Tarnakin18-Oct-05 1:31 
GeneralRe: Problem with clear method PinmemberJohny Nguyen19-Oct-05 19:52 
GeneralRe: Problem with clear method PinmemberAlexei Tarnakin20-Oct-05 1:36 
QuestionWhere is the end? PinmemberAlexei Tarnakin23-Aug-05 9:31 
AnswerRe: Where is the end? PinmemberHayder Marzouk23-Aug-05 23:29 
Generalimprovements PinmemberAlexei Tarnakin17-Jun-05 5:51 
GeneralRe: improvements PinmemberAlexei Tarnakin17-Jun-05 6:15 
GeneralRe: improvements PinmemberHayder Marzouk17-Jun-05 8:44 
GeneralRe: improvements PinmemberHayder Marzouk20-Jun-05 2:39 
GeneralRe: improvements PinmemberAlexei Tarnakin24-Jun-05 10:35 
GeneralRe: improvements PinmemberHayder Marzouk29-Jun-05 10:07 
GeneralRe: improvements PinmemberAlexei Tarnakin1-Jul-05 3:23 
GeneralRe: improvements PinmemberHayder Marzouk2-Jul-05 11:14 
GeneralRe: improvements PinmemberAlexei Tarnakin3-Jul-05 5:27 
GeneralRe:Improvements PinmemberHayder Marzouk3-Jul-05 11:43 
GeneralRe:Improvements PinmemberAlexei Tarnakin5-Jul-05 5:41 
GeneralRe:Improvements PinmemberAlexei Tarnakin5-Jul-05 6:07 
GeneralRe:Improvements PinmemberHayder Marzouk5-Jul-05 22:47 
GeneralRe:Improvements PinmemberHayder Marzouk5-Jul-05 22:56 
GeneralRe:Improvements PinmemberHayder Marzouk5-Jul-05 22:52 
GeneralRe:Improvements PinmemberAlexei Tarnakin6-Jul-05 0:30 
GeneralRe:Improvements PinmemberAlexei Tarnakin6-Jul-05 5:12 
GeneralRejectChanges method to BaseList object PinmemberJohny Nguyen15-Jun-05 23:45 
GeneralRe: RejectChanges method to BaseList object PinmemberHayder Marzouk16-Jun-05 1:16 
GeneralRe: RejectChanges method to BaseList object PinmemberJohny Nguyen16-Jun-05 19:06 
GeneralHowto Implement IEditableObject method PinmemberJohny Nguyen6-Jun-05 19:59 
GeneralRe: Howto Implement IEditableObject method PinmemberHayder Marzouk7-Jun-05 0:21 
QuestionHow to set ObjectStateType of Changed PinmemberJohny Nguyen6-Jun-05 0:08 
AnswerRe: How to set ObjectStateType of Changed PinmemberHayder Marzouk6-Jun-05 4:21 
GeneralFiltering Pinmembermailbox4spam8-May-05 12:56 
GeneralRe: Filtering PinmemberHayder Marzouk9-May-05 7:49 
GeneralProblem in Compare PinmemberMarc Brooks18-Apr-05 10:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 6 Jul 2005
Article Copyright 2005 by Hayder Marzouk
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid