Sort multiple columns while using a bindingsource or bindinglist

By : JF.
Source: Stackoverflow.com
Question!

I have a problem I am trying to fix and it's sorting a DataGridView on multiple columns. I have read that this option is not a feature built-in the DataGridView and I have to implement it. I have found multiple solutions, but none quite got to do the work.

I'm also quite a newbie in C# and I don't know much of the .Net library. I have also read on the MSDN site for info on different classes that might be of use, but no success.

Now, let's get to the point. I have a DataGridView, with a BindingList (originally, a BindingSource) that I want to sort, but by multiple keys. My DataGrid has 9 columns and the user should be able to sort on any column. For example, let's say my Datagrid has 3 columns, named : Index, ID, Name. The user wants to sort by Name, implicitly, the next order would be Index and then ID. So, in case 2 names are identical, Index should be the next sort option.

Any ideas how this can be made?

By : JF.


Answers

The BindingSource object has a Sort property that lets you sort its collection of objects by any property you want just like an ORDER BY clause in SQL. After sorting, you perhaps shall refresh your DataGridView through the Refresh() method, I think.

Have you tried that already?



This video can help you solving your question :)
By: admin