Aug 5, 2008 at 4:32 PM
Hi all,

I don't know if this is the right place to ask this but, I am using the repository factory in a project and now I would like to make my datagridviews sortable. I am binding the datagridviews to a bindingsource.

What would I need to do at to the source files created by the factory?

Aug 10, 2008 at 5:04 AM
Hi wilerk,

The GetAll methods generated by the Repository Factory return a List which contains a method to sort the collection items. For example, the following code get all customers from the database, call the sort method, and then bind to the DataGridView control:

            List<Customer> customers = repository.GetAllFromCustomer();
            dataGridView1.DataSource = customers;

In order to use the sort method, you will need to implement the IComparable interface in your business entity class. The Repository Factory generated your business entity class as partial, so you can extend it by implementing the IComparable interface. For example, if you want to sort customers by the CompanyName field, then you could extend the auto generated Customer class as:

    public partial class Customer: IComparable
        public int CompareTo(object obj)
            return CompanyName.CompareTo(((Customer)obj).CompanyName);

Another option would be to use the Sort method of the DataGridView control. However, it requires that the DataSource property binds to an object that implements the IBindingList interface. The GetAll methods return List<T> objects, so you would need to change the code to use a collection that implements IBindingList instead.

I hope this helps.

Aug 10, 2008 at 7:05 AM
Hi Luis,

Thanks for the solution, in the meantime I have converted the Lists to Datatables and bound them to my bindingsources.