Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Implementing a Sortable BindingList Very, Very Quickly

, 1 Dec 2008
A custom implementation of BindingList that provides sorting for every property of type T.
SortableBindingList.zip
SortableBindingList
SortableBindingList
Properties
DataSources
SaleDetail.datasource
Sale.datasource
Settings.settings
bin
Debug
SortableBindingList.vshost.exe.manifest
SortableBindingList.vshost.exe
SortableBindingList.exe
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SortableBindingList {
    public partial class FormDemo : Form {
        public FormDemo() {
            InitializeComponent();
            Load += OnLoad;
        }

        public void OnLoad(object source, EventArgs e) {

            var sales = new[] {
                new Sale(){
                    Client = "Jahmani Mwaura",
                    SaleDate = new DateTime(2008,1,1),
                    Salesman = "Gachie",
                    SaleDetails = new MySortableBindingList<SaleDetail>(){
                        new SaleDetail(){
                            Product = "Sportsman",
                            Quantity = 1,
                            UnitPrice = 80
                        },
                         new SaleDetail(){
                            Product = "Tusker Malt",
                            Quantity = 2,
                            UnitPrice = 100
                        },
                        new SaleDetail(){
                            Product = "Alvaro",
                            Quantity = 1,
                            UnitPrice = 50
                        }
                    }
                },
                new Sale(){
                    Client = "Ben Kones",
                    SaleDate = new DateTime(2008,1,1),
                    Salesman = "Danny",
                    SaleDetails = new MySortableBindingList<SaleDetail>(){
                        new SaleDetail(){
                            Product = "Embassy Kings",
                            Quantity = 1,
                            UnitPrice = 80
                        },
                         new SaleDetail(){
                            Product = "Tusker",
                            Quantity = 5,
                            UnitPrice = 100
                        },
                        new SaleDetail(){
                            Product = "Novida",
                            Quantity = 3,
                            UnitPrice = 50
                        }
                    }
                },
                new Sale(){
                    Client = "Tim Kim",
                    SaleDate = new DateTime(2008,1,1),
                    Salesman = "Kiplagat",
                    SaleDetails = new MySortableBindingList<SaleDetail>(){
                        new SaleDetail(){
                            Product = "Citizen Special",
                            Quantity = 10,
                            UnitPrice = 30
                        },
                        new SaleDetail(){
                            Product = "Burn",
                            Quantity = 2,
                            UnitPrice = 100
                        }
                    }
                }
            };

            saleBindingSource.DataSource = new MySortableBindingList<Sale>(sales);
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Muigai Mwaura
Technical Lead Olivine Technology
Kenya Kenya
Technical Lead, Olivine Technology - Nairobi, Kenya.
 
"The bane of productivity: confusing the rituals of work (sitting at your desk by 8:00am, wearing a clean and well pressed business costume etc.) with actual work that produces results."
 
Watch me!
Follow on   Twitter

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 2 Dec 2008
Article Copyright 2008 by Muigai Mwaura
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid