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();
                    }
                }
  • 相关阅读:
    java中的四种内部类
    09_TomCat_基础知识
    08_XML的解析_SAX解析
    IO流07_输入输出流总体系
    IO流06_处理流
    IO流05_OutputStream和Writer输出流
    IO流04_InputStream和Reader输入流
    IO流03_流的分类和概述
    IO流02_文件过滤器
    IO流01_File类
  • 原文地址:https://www.cnblogs.com/tansm/p/180629.html
Copyright © 2011-2022 走看看