zoukankan      html  css  js  c++  java
  • 关于Windows窗口保存前结束编辑的问题

    问题:
    窗口中控件绑定到dataSet1上,但调用this.BindingContext[this.dataSet1].EndCurrentEdit();
    程序并没有将当前的最新编辑存入dataSet1,

    解决方法:
    MSDN中说明了BindingContext的索引访问总是会返回一个BindingManagerBase,所以
    即使你传入了一个错误的参数,例如
    this.DataSet1也会有返回值,所以造成错误的认为调用是正确的。
    DataSet的绑定实际上内部是使用DataView实现的,所以有俩种解决方法:
    1、将控件绑定到DataView,而DataView关联DataSet,结束编辑时调用:
         BindingContext[this.dataview1].EndCurrentEdit();
         但这种方法如果有俩个表或更多调用就麻烦一些。
    2、直接寻找所有的绑定环境,并结束编辑。
                BindingManagerBase bm;
                foreach (System.Collections.DictionaryEntry item in
    this.BindingContext) {
                    bm = (item.Value as System.WeakReference).Target as
    BindingManagerBase;
                    if (bm != null) {
                        bm.EndCurrentEdit();
                    }
                }
  • 相关阅读:
    代码品质
    窖藏好题
    最后一次模拟
    几个有意思的题目
    【数组练习】
    【复习】图论
    【复习】后缀数组
    The Usage Of Difference Table
    【复习】NTT注意事项
    CF999E Reachability from the Capital
  • 原文地址:https://www.cnblogs.com/tansm/p/180629.html
Copyright © 2011-2022 走看看