DataGridView的Cell事件的先后触发顺序
最近正在使用“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事件的先后触发顺序的更多相关文章
- 关于JS 事件冒泡和onclick,click,on()事件触发顺序
今天在给JQgrid中的标签添加click事件的时候,发现一个问题. JQgrid的table中,点击任何位置,都会勾选点击行的checkbox,而我希望在点击我的标签的时候,不要勾选checkbox ...
- 针对focus和blur的Dom事件触发顺序
Dom事件触发顺序,拿文本框举例: 它会先触发focus事件,之后才会触发在有交点之后才能触发的一些如 click change 等事件(但如果有mousedown则先执行). 而相对于blur而言 ...
- .Net Install类的Install、Commit等事件触发顺序
.Net Install类的Install.Commit等事件触发顺序 空间 首先是Install其中调用base.Install过程中导致OnBeforeInstallOnAfterInstal ...
- Zendframework 模块加载事件触发顺序。
模块加载时事件触发的时间顺序: 0.loadModules(ModuleEvent::EVENT_LOAD_MODULES) 1. loadModule.resolve(ModuleEvent::E ...
- sencha touch list(列表) item(单行)单击事件触发顺序
测试代码如下 Ext.define('app.view.new.List', { alternateClassName: 'newList', extend: 'app.view.util.MyLis ...
- DataGridView在Cell编辑状态响应回车键下的KeyPress/KeyDown/KeyUp事件
我们知道由于DataGridView的单元格DataGridCell处于编辑的时候,当你按Enter键,那么DataGridView是不会激发KewPress/KeyDown/KeyUp这些事件的,因 ...
- Javascript事件触发顺序
html标签是有子和父的,这个时候就出现了事件触发顺序的问题,比如: <!DOCTYPE html> <html> <head> <style> .fi ...
- 2019-11-29-WPF-多个-StylusPlugIn-的事件触发顺序
原文:2019-11-29-WPF-多个-StylusPlugIn-的事件触发顺序 title author date CreateTime categories WPF 多个 StylusPlugI ...
- 2019-10-21-WPF-多个-StylusPlugIn-的事件触发顺序
title author date CreateTime categories WPF 多个 StylusPlugIn 的事件触发顺序 lindexi 2019-10-21 08:33:15 +080 ...
随机推荐
- Debian系统vim中文显示乱码问题
网上查的一堆东西好像都不灵,试了半天! 先安装中文字体:sudo aptitude install fonts-arphic-uming fonts-wqy-zenhei 然后:sudo locale ...
- 编写可维护的JavaScript
第一章 1.基本的格式化 1.1推荐使用Tab键插入4分字符 1.2语句结尾要使用分号 1.3一行的长度最好不要超过80个字符 1.4通常在运算符后换行,下一行增加2个层级的缩进 1.5推荐在以下场景 ...
- FMDB读取Datetime类型值为1970的问题
1.问题 今天使用FMDB做一个例子程序,新建的一张表有一个datetime字段,数据库有默认值,大概如下 CREATE TABLE [ConsumptionType] ([id] INTEGER P ...
- ArcGIS百米网格自动生成
最近需要用百米网格进行空间叠加分析,首先得自动生成百米网格数据.经过查找,发现ARCgis可以自动生成网格.方法如下 2.创建格网(Creat Fishnet).需要用到ArcGIS的ArcToolb ...
- 如何运用boolean跳出循环
用布尔类型跳出循环:1.首先申明一个布尔变量:boolean y =false:申明位置在:方法内,循环外:public void s(){//在此申明布尔变量:for(){}}if(!y){}2,进 ...
- 5.webService拦截器
CXF为什么要设计拦截器? 为了在webservice请求过程中,能动态操作请求和响应数据, CXF设计了拦截器. 拦截器分类 1.按所处的位置分:服务器端拦截器,客户端拦截器 2.按消息的方向分:入 ...
- Win10 设置外网多用户远程桌面连接
主要原理:利用路由器的虚拟服务器功能,将内网的Ip地址通过端口映射提供给外网,使得外网能够访问到目的主机. 1. 配置路由器上的虚拟服务器,假设目的主机内网的ip为192.168.1.100,则配置如 ...
- PN结的形成
P型半导体 在纯净的硅晶体中掺入3价元素如硼,使之取代晶格中硅原子的位置,就形成了P型半导体.在P型半导体中,空穴为多字,自由电子为少子,主要靠空穴导电.掺入的杂质越多,空穴的浓度就越大,导电性就越强 ...
- poj 1806 分块模拟
Manhattan 2025 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1318 Accepted: 703 Des ...
- 黑马程序员——HTML表格布局
---------------------- <a href="http://edu.csdn.net"target="blank">ASP.Net ...