摘要: 有兄弟绑定了一个ArrayList到 System.Windows.Forms.DataGrid, 然后设置AllowSorting 为 True,但是发现显示出的DataGrid还是不能排序的说。
在MSDN上相关的帮助那里没有看到甚么有用的东东,它只是说如果绑定 DataView/DataViewManager ,你可以如何如何。对ArrayList或者对象数组没有就没话说了。上Google查也没有找到什么有意义的东西,最后实在没有办法只有拿ILDASM 来偷窥了...
在里面找到一个名为AllowSortingChanged的私有方法,里面调用到了一个IBindingList的RemoveSort 方法:
......... IL_002a: castclass [System]System.ComponentModel.IBindingList
IL_002f: callvirt instance void [System]System.ComponentModel.IBindingList::RemoveSort() IL_0034: ret } // end of method DataGrid::AllowSortingChanged
然后的事情就很简单了,看了看IBindingList的接口,SortProperty/SortDirection属性和ApplySort/RemoveSort 方法明显就是给DataGrid准备的,基本上就可以确定了:
只有实现了IbindingList的DataSource才可以在DataGrid里排序.
-----------------偶一般不喜欢只写一件事情,No2 Coming ------------------------
MSDN 看到了一篇文章:On the Way to Mastering ASP.NET: Introducing Custom Entity Classes,
偶喜欢它对System.Data 缺陷的评论,它把使用DataSet的缺点展示的非常清楚,但是文章后半段对Entity Class的介绍(实现)就让人觉得有点简单--换句话说,它很好的提出了问题,但是没有很好的解决.....
不过文章还是不错di,而且里面还给了你一堆Link引导你去近一步深入某个问题。
"Never return a class from the System.Data or child namespace from the DAL" 是这篇文章里提出的一个Rule,我以为,用它来做文章的标题更合适的说
...[
阅读全文]