Certain types of data sources work best for DataGrid depending on your scenario. Following are some tips which you should keep in mind when choosing a data source for your DataGrid application:
Using Linq to SQL will break sorting. In the Linq to SQL case, SQL returns Table<T> which does not implement ITypedList and therefore prevents BindingListCollectionView from correctly sorting the items. Any Linq providers that return IBindingList will see this issue. This will be fixed in an upcoming release. Until that fix is available, we recommend that you do not use a Linq to SQL (or any other provider which returns IBindingList) data source if your DataGrid requires the sorting feature. Since Linq to objects returns IEnumerable, Linq to object data sources will not break sorting.
我也是用linq to sql 作为dataGridView的数据源代码如下:
dataGridView1.DataSource=(from p in listUser
select p).toList();
点击dataGridView的Column Header无法实现排序,如果DataGridView的数据源是dataSet或DataTable就能很好地实现排序。这是为什么?