How to enable sorting on a DataGridView that is bound to a LINQ to Entities query?
I have a query as such (simp开发者_如何学JAVAlified):
var q = from t in _entities.Table
order by t.Id
select new
{
Id = t.Id,
Name = t.FullName
};
MyDataGridView.DataSource = q;
However, it seems that I can't click on the Column Header and get it to sort (switching between ascending and descending) on either the ID or Name. I verified that the SortMode is set to automatic. There is no need to requery the database, I just want to sort what is already displayed on the grid.
use linq to manually sort e.g q.sort();
or
using Generic BindingList http://msdn.microsoft.com/en-us/library/aa480736.aspx
similar to this http://www.tech.windowsapplication1.com/content/sortable-binding-list-custom-data-objects
精彩评论