最近正在使用“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. javaWeb开发小工具--MyCommonUtils

    MyCommonUtils 参考一些资料,写了这个工具类.在这个工具类中,主要实现了2个方法: 1.生成随机的序列号 uuid(): 2.将Map中的数据封装到javaBean对象中toBean(Ma ...

  2. Arcgis API For IOS扩展AGSDynamicLayer新旧版API对比

    AGSDynamicLayer(ForSubclassEyesOnly) Category Reference Description This category organizes the meth ...

  3. zabbix利用mutt和msmtp配置邮件报警

    Mutt安装 yum –y install mutt msmtp安装 yum –y install openssl openssl-devel libntlm libntlm-devel cyrus- ...

  4. python中协程的使用示例

    例子1 把字符串分割为列表 def line_splitter( delimiter = None ): print( 'ready to split' ) result = None while T ...

  5. vi命令模式下快速注释代码的方法

    进入http://www.vim.org/scripts/script.php?script_id=1528 点击这个链接下载comments.vim这个插件 然后把它放入到./vim/plugin下 ...

  6. ruby使用DBI连接MySQL数据库发生异常:in `error': Can't connect to MySQL server on 'localhost' (10061) (DBI::DatabaseError)

    Ruby使用DBI连接MySQL数据库一般为: require "dbi" dbh = DBI.connect("dbi:Mysql:test:localhost&quo ...

  7. MSP430单片机的位操作

    MSP430单片机属于RISC(Reduced Instruction Set Computer)型处理器.与普通的51单片机的复杂指令集相区别.普通51单片机执行一条指令最少需要12个时钟周期,而R ...

  8. 树莓派3B安装pybluz

    按如下流程: apt-get install python-dev apt-get install python-pip apt-get install libbluetooth-dev pip in ...

  9. HttpURLConnection使用getInputStream无法执行

    url = new URL(urlStr); urlConn = (HttpURLConnection) url.openConnection(); // 设置请求方式为"GET" ...

  10. mySQL中删除unique key的语法

    CREATE TABLE `good_booked` (  `auto_id` int(10) NOT NULL auto_increment,  `good_id` int(11) default ...