Click here to Skip to main content
13,095,445 members (64,887 online)
Click here to Skip to main content

Stats

168.8K views
3.6K downloads
83 bookmarked
Posted 1 Dec 2008

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
SortableBindingList
Properties
DataSources
SaleDetail.datasource
Sale.datasource
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!

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 2 Dec 2008
Article Copyright 2008 by Muigai Mwaura
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid