最近正在使用“DataGridView”对一个旧的Vs 2003开发的WINDOWS应用程序进行改造。

发现Vs 2003中的"DataGrid"中的一些事件已经在新的控件DataGridView中取消了,但是却多了很多的“Cell”事件,真是被搞的头大,主要是不了解各个事件的先后触发顺序。

所以写了一个小程序,用来测试常用的Cell事件及顺序。

第一种顺序,即不进行Cell编辑的情况下:

CellEnter-发生于 DataGridView 单元格的焦点获取的时候,或是单元格收到输入焦点的时候。


CellLeave-发生于单元格失去输入焦点时,而且现在是当前的单元格。


CellValidating-发生于单元格失去输入焦点时,同时触发数据验证,进行数据验证。


CellValidated –发生于单元格完成数据验证之后。

各事件的触发时间顺序图如下,由于CellEnter是第一个被触发,后续事件,都是由人工去进行触发的,所以时间间隔相对有点长。

 

第二种对单元格进行编辑之后的事件顺序

CellEnter-发生于 DataGridView 单元格的焦点获取的时候,或是单元格收到输入焦点的时候。


CellBeginEdit –发生于选中的单元格进入编辑模式的时候。


CellLeave-发生于单元格失去输入焦点时,而且现在是当前的单元格。


CellValidating-发生于单元格失去输入焦点时,同时触发数据验证,进行数据验证。

CellValueChanged-发生于单元格中的值发生变更时。


CellValidated -发生于单元格完成数据验证之后。


CellEndEdit-发生于当前所选中的单元格退出编辑模式时。

各事件的触发时间顺序图如下,由于CellEnter是第一个被触发,后续事件,都是由人工去进行触发的,所以时间间隔相对有点长。

测试代码如下:

private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)

        {

            txtCellLeave.Text = string.Format("Time={0};{1}事件,Row:col={2},{3}",  DateTime.Now.ToString("HH:mm:ss.fff"), "CellLeave", e.RowIndex, e.ColumnIndex);

            System.Threading.Thread.Sleep();

        }

        private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)

        {

            txtCellValidated.Text = string.Format("Time={0};{1}事件,Row:col={2},{3}",  DateTime.Now.ToString("HH:mm:ss.fff"), "CellValidated", e.RowIndex, e.ColumnIndex);

            System.Threading.Thread.Sleep();

        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)

        {

            txtCellEndEdit.Text = string.Format("Time={0};{1}事件,Row:col={2},{3}", DateTime.Now.ToString("HH:mm:ss.fff"), "CellEndEdit", e.RowIndex, e.ColumnIndex);

            System.Threading.Thread.Sleep();

        }

        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)

        {

            txtCellBeginEdit.Text = string.Format("Time={0};{1}事件,Row:col={2},{3}", DateTime.Now.ToString("HH:mm:ss.fff"), "CellBeginEdit", e.RowIndex, e.ColumnIndex);

            System.Threading.Thread.Sleep();

        }

        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)

        {

            txtCellValidating.Text = string.Format("Time={0};{1}事件,Row:col={2},{3}", DateTime.Now.ToString("HH:mm:ss.fff"), "CellValidating", e.RowIndex, e.ColumnIndex);

            System.Threading.Thread.Sleep();

        }

        private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)

        {

            txtCellEnter.Text = string.Format("Time={0};{1}事件,Row:col={2},{3}", DateTime.Now.ToString("HH:mm:ss.fff"), "CellEnter", e.RowIndex, e.ColumnIndex);

            System.Threading.Thread.Sleep();

        }

        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)

        {

            txtCellValueChanged.Text = string.Format("Time={0};{1}事件,Row:col={2},{3}", DateTime.Now.ToString("HH:mm:ss.fff"), "CellValueChanged", e.RowIndex, e.ColumnIndex);

            System.Threading.Thread.Sleep();

        }

        WBK_COP_PDE pde = null;

        private WBK_COP_PDE ReadDataSource()

        {

            string path = string.Format("{0}\\{1}", Application.StartupPath, "WBK_COP_PDE_datasource.XML");

            pde = XMLHelper.ParseXML<WBK_COP_PDE>(path, new WBK_COP_PDE()) as WBK_COP_PDE;

            return pde;

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            WBK_COP_PDE pde = ReadDataSource();

            BindData();

        }

        private void BindData()

        {

            dataGridView1.DataSource = pde.WBK_PDE_LIST_ORG.WBK_PDE_ITEM_ORGS;

        }

DataGridView的Cell事件的先后触发顺序的更多相关文章

  1. 关于JS 事件冒泡和onclick,click,on()事件触发顺序

    今天在给JQgrid中的标签添加click事件的时候,发现一个问题. JQgrid的table中,点击任何位置,都会勾选点击行的checkbox,而我希望在点击我的标签的时候,不要勾选checkbox ...

  2. 针对focus和blur的Dom事件触发顺序

    Dom事件触发顺序,拿文本框举例: 它会先触发focus事件,之后才会触发在有交点之后才能触发的一些如 click  change 等事件(但如果有mousedown则先执行). 而相对于blur而言 ...

  3. .Net Install类的Install、Commit等事件触发顺序

    .Net Install类的Install.Commit等事件触发顺序 空间   首先是Install其中调用base.Install过程中导致OnBeforeInstallOnAfterInstal ...

  4. Zendframework 模块加载事件触发顺序。

    模块加载时事件触发的时间顺序: 0.loadModules(ModuleEvent::EVENT_LOAD_MODULES) 1.  loadModule.resolve(ModuleEvent::E ...

  5. sencha touch list(列表) item(单行)单击事件触发顺序

    测试代码如下 Ext.define('app.view.new.List', { alternateClassName: 'newList', extend: 'app.view.util.MyLis ...

  6. DataGridView在Cell编辑状态响应回车键下的KeyPress/KeyDown/KeyUp事件

    我们知道由于DataGridView的单元格DataGridCell处于编辑的时候,当你按Enter键,那么DataGridView是不会激发KewPress/KeyDown/KeyUp这些事件的,因 ...

  7. Javascript事件触发顺序

    html标签是有子和父的,这个时候就出现了事件触发顺序的问题,比如: <!DOCTYPE html> <html> <head> <style> .fi ...

  8. 2019-11-29-WPF-多个-StylusPlugIn-的事件触发顺序

    原文:2019-11-29-WPF-多个-StylusPlugIn-的事件触发顺序 title author date CreateTime categories WPF 多个 StylusPlugI ...

  9. 2019-10-21-WPF-多个-StylusPlugIn-的事件触发顺序

    title author date CreateTime categories WPF 多个 StylusPlugIn 的事件触发顺序 lindexi 2019-10-21 08:33:15 +080 ...

随机推荐

  1. 记录参加“牛津计划.Docker在线黑客松”比赛的过程

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  2. 使用IConfigurationSectionHandler在web.config中增加自定义配置

    一. 场景    这里仅举一个简单应用的例子,我希望在web.config里面增加网站的基本信息,如:网站名称,网站版本号,是否将网站暂时关闭等.二. 基本实现方法1. 定义配置节点对应的类:Site ...

  3. DFS security warning and use group policy to set up internet security zones

    Opening a file from a DFS domain share shows a security warning while openning from the server share ...

  4. windows编程:第一个windows程序

    #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <windowsx.h> #include <math ...

  5. 工作随笔——UIButton的EdgeInsets + Swift中的正则表达式;

    1.UIButton的EdgeInsets UIButton的EdgeInsets方法,是用来设置title和image对于上左下右四个方向的偏移,但是很奇怪的是,刚开始只有Image,titile也 ...

  6. ajax 跨域请求时url参数添加callback=?会实现跨域问题

    例如: 1.在 jQuery 中,可以通过使用JSONP 形式的回调函数来加载其他网域的JSON数据,如 "myurl?callback=?".jQuery 将自动替换 ? 为正确 ...

  7. 利用nodejs实现登录并转码视频(原创)

    nodejs的出现让前端人员可以使用js打造后台,也许哪天就真的摆脱了对java或者php的依赖了. 今天跟大家分享一个利用nodejs接受前端post请求,并实现视频转码的这样一个例子.视频转码用到 ...

  8. Irrlicht 鬼火

    1.下载引擎 2.引入头文件 在VS2010下新建项目,项目->属性->配置属性->VC++目录 在包含目录中:添加 引擎安装目录\include\ 在库目录中:添加 引擎安装目录\ ...

  9. 第十章 PageRank——Google的民主表决式网页排名技术

    搜索引擎的结果取决于两组信息:网页的质量信息,这个查询与每个网页的相关性信息.这里,我们介绍前一个. 1.PageRank算法原理 算法的原理很简单,在互联网上,如果一个网页被很多其他网页所链接,说明 ...

  10. linux编译php的c扩展

    第一步:安装php5 第二步:打开终端[为来方便,这里使用root用户],使用CD命令进入到php5源码包的ext目录 第三步:在终端键入以下命令 ./ext_skel --extname=extes ...