最近正在使用“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. 利用office2000组件进行填充打印报不支持集合。 (Exception from HRESULT: 0x80020011 (DISP_E_NOTACOLLECTION))

    环境:win2008 64位+.net4.0 +office2000 错误提示: 不支持集合. (Exception from HRESULT: 0x80020011 (DISP_E_NOTACOLL ...

  2. 【转】Python中的赋值、浅拷贝、深拷贝介绍

    这篇文章主要介绍了Python中的赋值.浅拷贝.深拷贝介绍,Python中也分为简单赋值.浅拷贝.深拷贝这几种"拷贝"方式,需要的朋友可以参考下   和很多语言一样,Python中 ...

  3. UVALive 2191 Potentiometers (树状数组)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  4. linux mysql

    安装mysql 1.使用rpm 安装mysql 或者使用yum安装 使用rpm 安装 下载 Centos 7 所需要的mysql包 tar -xf 解压整合包 根据依赖 安装 common>li ...

  5. 关于H5本部缓存localStorage,sessionStorage

    HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessionStorage - 针对一个 session 的数据存储 之前,这些都是由 coo ...

  6. (转)Android开发出来的APP在手机的安装路径是?

    一.安装路径在哪? Android应用安装涉及到如下几个目录: system/app系统自带的应用程序,无法删除.data/app用户程序安装的目录,有删除权限.安装时把apk文件复制到此目录.dat ...

  7. 套题 codeforces 361

    A题((Mike and Cellphone) 看起来好像需要模拟数字键位的运动,可是,只要判断出那些必然YES的数字组合不就好了么 #include <cstdio> #include ...

  8. Linux内核--网络栈实现分析(四)--网络层之IP协议(上)

    本文分析基于Linux Kernel 1.2.13 原创作品,转载请标明http://blog.csdn.net/yming0221/article/details/7514017 更多请看专栏,地址 ...

  9. 使用Spring注解来简化ssh框架的代码编写

     目的:主要是通过使用Spring注解的方式来简化ssh框架的代码编写. 首先:我们浏览一下原始的applicationContext.xml文件中的部分配置. <bean id="m ...

  10. EBS excel模板xml publisher开发

    前提: BI publisher下载地址: http://www.oracle.com/technetwork/middleware/bi-publisher/downloads/index.html ...