简体   繁体   English

C#SortableList未在DataGridView中排序

[英]C# SortableList not sorting in DataGridView

I have a generic form for displaying a list of items. 我有一个用于显示项目列表的通用表单。 This is usually an "IQueryable" based on a Linq-2-sql query, but I want to be able to show any list. 这通常是基于Linq-2-sql查询的“ IQueryable”,但我希望能够显示任何列表。 I've added code to my project so I can use SortableLists instead of the normal List, which does not support sorting by default. 我已将代码添加到项目中,因此可以使用SortableLists代替普通的List,该列表默认情况下不支持排序。 I can pass the Sortable list as IQueryable, but as a result sorting wont working. 我可以将Sortable列表作为IQueryable传递,但结果排序将无法进行。 Is there a way to make the SortableList IQueryable while keeping it sortable? 有没有一种方法可以使SortableList IQueryable保持可排序?

I've found a solution myself: Instead of using the IQueryable directly as the datsource of the grid (which I do with Linq-to-sql queries), I make a new SortableList by doing "new SortableList(myQuery.ToList())" and use that as datasource. 我自己找到了一个解决方案:我没有直接将IQueryable用作网格的数据源(我使用Linq-to-sql查询),而是通过执行“ new SortableList(myQuery.ToList())创建了一个新的SortableList。 ”,并将其用作数据源。 And voila, it sorts. 瞧,排序。

(So, no you cannot (always) sort the IQueryable.) (因此,不,您不能(始终)对IQueryable进行排序。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM