数据绑定常见问题
2009-07-09 15:15
357 查看
1、两个GRID绑定父子关系的数据源绑定。如果先新增子数据源记录,则会出现异常:System.MissingMethodException: Constructor on type
'System.ComponentModel.IBindingList' not found.
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
这是因为父对象还未创建记录。
解决方法:
1、在子数据源新增对象时判断:
if (((System.ComponentModel.IBindingList)this.childBindingSource.List).AllowNew )
{
this.childBindingSource.AddNew();
}
2、父数据源的ListChanged事件中,确保主数据源在无数据时,子数据源无法先新增。
private void leftBindingSource_ListChanged(object sender, ListChangedEventArgs e)
{
Console.WriteLine("leftBindingSource_ListChanged");
if (leftBindingSource.Current == null)
this.edgRight.AllowUserToAddRows = false;
else
this.edgRight.AllowUserToAddRows = true;
}
'System.ComponentModel.IBindingList' not found.
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
这是因为父对象还未创建记录。
解决方法:
1、在子数据源新增对象时判断:
if (((System.ComponentModel.IBindingList)this.childBindingSource.List).AllowNew )
{
this.childBindingSource.AddNew();
}
2、父数据源的ListChanged事件中,确保主数据源在无数据时,子数据源无法先新增。
private void leftBindingSource_ListChanged(object sender, ListChangedEventArgs e)
{
Console.WriteLine("leftBindingSource_ListChanged");
if (leftBindingSource.Current == null)
this.edgRight.AllowUserToAddRows = false;
else
this.edgRight.AllowUserToAddRows = true;
}
相关文章推荐
- springMVC对简单对象、Set、List、Map的数据绑定和常见问题(一)
- 再谈angularJS数据绑定机制及背后原理—angularJS常见问题总结
- springMVC对简单对象、Set、List、Map的数据绑定和常见问题
- Windows Forms数据控件和数据绑定常见问题
- springMVC对简单对象、Set、List、Map的数据绑定和常见问题(二)
- springMVC对简单对象、Set、List、Map的数据绑定和常见问题(一)
- springMVC对简单对象、Set、List、Map的数据绑定和常见问题(三)
- springMVC对简单对象、Set、List、Map的数据绑定和常见问题(二)
- wpf数据绑定常见问题
- springMVC对简单对象、Set、List、Map的数据绑定和常见问题(三)
- [ASP.NET] 将数据绑定到DropDownlist中的常见问题
- vue数据绑定数组,改变元素时不更新view问题
- 使用Vue如何写一个双向数据绑定(面试常见)
- 有关绑定没有数据显示的问题
- Ajax请求ashx返回json数据的常见问题
- DataGridview中DataGridViewComboBoxColumn数据绑定的问题
- windows8中的Slider数据绑定问题
- EF做数据绑定时一些神奇问题
- 关于LISTBOX绑定数据再刷新的问题
- 三维软件开发笔记---调错DataGrid控件数据绑定无法显示问题