最近正在使用“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. 让C++程序打印自身源码

    本人原创文章,欢迎阅读,禁止转载. 这绝对是惊艳到让你眼前一亮(为了简洁,故意没考虑资源问题和编译警告). #include <iostream> #include <fstream ...

  2. ContentProvider要点复习

    ContentProvider要点复习 ContentProvider作为四大组件之一,发挥着举足轻重的作用.与之相关联的另外两个类分别是ContentResolver和ContentObserver ...

  3. easyui datagrid中关联combox

    datagrid中列上关联combobox{ field: 'SysCode', title: '系统代码', width: 150, align: 'left', editor: { type: ' ...

  4. [UCSD白板题] Least Common Multiple

    Problem Introduction The least common multiple of two positive integers \(a\) and \(b\) is the least ...

  5. angular+requirejs前端整合

    requirejs或者seajs我相信在前端的开发工作中经常使用到,而angular,这个强大的web前端框架很多公司也在引入.本文主要记录自己在工作学习中如何对angular跟requirejs进行 ...

  6. js获取select标签选中的值

    <p>        城市:         <select id="Select1" name="D1">            &l ...

  7. 深入浅出C#中的静态与非静态

    C#语言静态类 vs 普通类  C#语言静态类与普通类的区别有以下几点: 1)C#语言静态类无法实例化而普通类可以: 2)C#语言静态类只能从System.Object基类继承:普通可以继承其它任何非 ...

  8. ubuntu使用经验整理

     ===================================================== 清理/boot分区 =================================== ...

  9. redis/php redis扩展 安装

    作者:silenceper 日期:2013-10-03 原文地址: http://silenceper.com/archives/952.html 我是在CentOS 6.3 中进行的. 使用到的软件 ...

  10. 解剖SQLSERVER 第十六篇 OrcaMDF RawDatabase --MDF文件的瑞士军刀(译)

    解剖SQLSERVER 第十六篇 OrcaMDF RawDatabase --MDF文件的瑞士军刀(译) http://improve.dk/orcamdf-rawdatabase-a-swiss-a ...