winforms - 如何让我的绑定(bind)源支持排序?

标签 winforms entity-framework-5 bindingsource

我正在尝试制作一个主详细信息表单,其中主记录绑定(bind)到一个绑定(bind)源,详细信息 datagridview 绑定(bind)到第二个绑定(bind)源

它工作得很好,只有 childBindingSource.SupportSorting 属性为 false。 masterBindingSource.SupportsSorting 为 true。有没有办法让 childBindingSource 支持排序 - 鉴于它基于另一个支持排序的绑定(bind)源?

masterBindingSource.DataSource = GetBindingSource()   // .SupportsSorting = true
childBindingSource.DataSource = masterBindingSource   // .SupportsSorting = false
childBinding.DataMember = ChildItems

private BindingSource GetBindingSource()
{
   DbSet<ContactEvent> dset = Db.ContactEvents;
   IOrderedQueryable<ContactEvent> qry = dset.Where(p => p.Id > 0).OrderBy(x => x.Id);
   qry.Load();

   BindingList<ContactEvent> bindinglist = dset.Local.ToBindingList();
   var bindingSource = new BindingSource();
   bindingSource.DataSource = bindinglist;
   return bindingSource;
}

最佳答案

在一些帮助下,我们使用 this link at codeplex

我必须更改我的类以使用 SortableBindingList 而不是 BindingList。 对我来说有趣的是,BindingList 对于主级别的网格来说已经足够好了,但对于包含详细信息的网格来说却不够。

关于winforms - 如何让我的绑定(bind)源支持排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14452195/

相关文章:

c# - 我使用方法调用程序删除我的用户控件,但是当我使用 foreach 时,它的计数总是减 1

.net - 允许用户对 DataGridView 中的 LINQ 查询中的列进行排序

C# 从 BindingSource 刷新文本框

c# - 表格 "Not responding"如果之前没有显示

c# - 最小化/恢复窗口时是否可以禁用动画?

mysql - Entity Framework 代码优先与 MySql 错误

asp.net - 将对象列表添加到 Entity Framework 中的数据库上下文

c# - Entity Framework - 如何使用 lambda 通过一个查询选择每个 IDNumber 的第一行

C#/.NET : Move to desired Item in BindingNavigator

c# - 将 AxShockwaveFlash Flash 对象写入文件 C#