How do I implement automatic sorting of DataGridView?

We use BindingListView to bind List<T>s to DataGridViews, and it’s worked beautifully for us.

Here is a very simple example of creating a view of a list of objects (in C#):

List<Customer> customers = GetCustomers();
BindingListView<Customer> view = new BindingListView<Customer>(customers);
dataGridView1.DataSource = view;

Check out https://stackoverflow.com/a/17952576/116891 for a lot more details about DGV sorting and databinding.

If you don’t want to add something that heavy, you can try this implementation of a SortableBindingList<T> (with updates).

Both give you sorting right out of the box, and BindingListView is even faster than DataViews, according to their benchmarks.

Leave a Comment