BindingSource的DataMember设为表间关系时,BindingSource.List转化成DataView出错?
Visual Studio 2010 开发环境。数据库应用程序的开发。
在一对多的父子表窗体中,父表的BindingSource,其DataSource属性设为某个DataSet,DataMember属性设为DataSet中的某个DataTable。这样将父表的BindSource.List转化成DataView是没有问题的。
而子表的BindingSource,其DataSource属性设为父表的BindingSource,DataMember属性设为父子表之间的关系。这时将出现很奇怪的现象:想将子表的BindSource.List转化成DataView,有时是可以的,有时将不行!弹出的错误提示是:
Unable to cast object of type 'System.ComponentModel.BindingList' 1[System.ComponentModel.IBindingList]' to type 'System.Data.DataView'.
具体好像是:在先加载了父表、且父表中的记录不为空的情况下,子表的转化将不出现问题;而若尚未加载过父表、或父表中的记录为空的情况下,一旦执行子表的上述转化,就将出错。
那么请问:像这种情况,又该如何对子表进行转化,以获取子表所绑定的DataTable对象呢?
先谢了!