我正在尝试制作一个主详细信息表单,其中主记录绑定(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/