开发者

Sort multiple columns while using a bindingsource or bindinglist

开发者 https://www.devze.com 2022-12-22 19:20 出处:网络
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 fou

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 开发者_Python百科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?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号