使用两个不同的列对 BindingSource 进行排序
我目前正在尝试修复 VS 2008 中使用 C# 的系统中的一些错误。
问题如下:
客户端希望对某些控件进行排序。该窗体由四个控件组成。其中两个与 BindingSourceA 绑定,另外两个与 BindingSourceB 绑定。 与 BindingSourceA 绑定的控件之一显示代码,另一个显示名称。 BindingSourceB 也是如此。 Control1 需要使用代码显示成员/列进行排序,而 Control2 需要使用名称显示成员/列进行排序。控件 3 和 4 也是如此。 经过一番研究后,我发现 BindingSourceA.Sort = "Code ASC 和 BindingSourceB.Sort = "Code ASC 可以完成这项工作。 但我需要类似于 BindingSourceA.Sort = "Code ASC, Name ASC" 的东西,这也是我摸索的结果。问题是它对我不起作用……要么是其中之一,要么是另一个。我什至尝试过 BindingSourceA.Sort = "Code ASC"; BindingSourceA.Sort = "Name ASC"; 但这也不起作用..
如果您需要更多信息,请告诉我。
提前致谢
Im currently trying to fix some bugs in a system using C# in VS 2008.
The problem goes as follows:
The client wants some controls to be sorted. The form consists of four controls. Two of which are binded with BindingSourceA lets say and the other two with BindingSourceB.
One of the controls binded with BindingSourceA displays a code and the other one a name. Same goes for BindingSourceB.
Control1 needs to be sorted using the Code display member/column while Control2 needs to be sorted using the Name display member/column. Same goes for controls 3 and 4.
After some poking around i found that BindingSourceA.Sort = "Code ASC and BindingSourceB.Sort = "Code ASC do the job.
BUT i need something along the lines of BindingSourceA.Sort = "Code ASC, Name ASC" which also was the result of my poking around. The problem is that it doesnt do the trick for me.. Its either one or the other. I even tried BindingSourceA.Sort = "Code ASC"; BindingSourceA.Sort = "Name ASC"; but that didnt work either..
Let me know if you need anymore info.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据绑定的排序支持实际上完全取决于底层数据实现,以及它是否支持
IBindingList.SupportsSorting
,IBindingListView.SupportsAdvancedSorting
,两者都不是,或两者兼而有之。就个人而言:只需单独对数据进行排序(也许通过 LINQ),然后对其进行数据绑定。避免整个问题并适用于任何数据源。The sorting support of data-bindings actually depends entirely on the underlying data implementation, and whether it supports
IBindingList.SupportsSorting
,IBindingListView.SupportsAdvancedSorting
, neither, or both. Personally: just sort the data separately (via LINQ, perhaps), and then data-bind it. Avoids the entire issue and works for any data source.