未触发Datagrid cellvalidating事件 [英] Datagrid cellvalidating event not fired

查看:124
本文介绍了未触发Datagrid cellvalidating事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

vs2008 + datagridview + cellvalidating事件未触发....同时更改了特定单元格的值.


任何帮助!!!

hi!!

vs2008 + datagridview + cellvalidating event not fire....while change the value of particular cell.


any Help!!!

推荐答案

如果要在仍在编辑单元格的同时验证数据输入,则每次开始编辑菜单时都需要设置一个按键处理程序.您需要验证的单元格.

为此,您必须处理DataGridview.EditingControlShowing事件,并在其中附加按键处理程序.

If you want to validate data entry while still editing a cell you will need to set up a key press handler each time you begin editing a cell you need to validate.

To do that you must handle the DataGridview.EditingControlShowing event, and within that you will attach the keypress handler.

private void dataGridView1_EditingControlShowing(object sender,
    DataGridViewEditingControlShowingEventArgs e)
{
    dataGridView1.EditingControl.KeyPress -= new KeyPressEventHandler(MyKeyPressHandler);
    dataGridView1.EditingControl.KeyPress += new KeyPressEventHandler(MyKeyPressHandler);
}



通过检查EditingControlShowing处理程序的参数,您可以选择要验证的单元格,也可以对每个单元格使用不同的按键处理程序.
请注意,按键处理程序在添加之前已被删除.这是为了防止在您继续进入单元格时建立相同的处理程序.删除不存在的处理程序(在第一次进入时)不是问题.



By checking the arguments to the EditingControlShowing handler you can be selective about the cells you decide to validate, or use different key press handlers for each cell.
Note that the key press handler is removed before it is added. This is to prevent a build up of identical handlers when you keep entering a cell. Removing a handler which doesn''t exist (on first entry) isn''t a problem.


这篇关于未触发Datagrid cellvalidating事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆