林使用LINQ ...更具体地,排序PLINQO。反正以下是我绑定到一个DataGridView查询(的WinForms)为例:的WinForms DataGridView中使用LINQ
public static List<Task> GetUserTasks(Guid userID) {
using (myDataContext ctx = new myDataContext()) {
try {
return ctx.Manager.Task.GetByUserID(userID).ToList();
} catch (Exception) {
throw;
}
}
}
在我的UI,我有以下的设置绑定:
BindingSource bs = new BindingSource();
bs.DataSource = DUtasks.GetUserTasks(User.Current.UserID);
dgvTasks.DataSource = bs;
它的工作原理,但没有排序是可能的。我试过“AsEnumerable()”而不是“ToList()”,但由于某种原因,抛出了“异议引用”错误。关于如何在这方面继续前进的任何想法?
非常感谢!
HI劫匪。不幸的是,这不起作用。我已经尝试了一个“orderby”追加到查询没有结果。我在每列设置为自动排序属性(哦,顺便说一句,我喜欢选择不自动生成列,如果这使差异。),所以我知道,只要我有它的权利SortGlyph应该出现,对? – Shalan 2009-10-13 16:57:51