dgvConfig.DataSource = CreateTable();
dgvConfig.Columns["编号"].ReadOnly = true; //只读
dgvConfig.AllowUserToAddRows = false; //不允许添加新行
dgvConfig.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dgvConfig_EditingControlShowing);

  

 void dgvConfig_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridViewTextBoxEditingControl cotrol = (DataGridViewTextBoxEditingControl)e.Control;
cotrol.KeyPress += new KeyPressEventHandler(Edit_Value);
cotrol.MaxLength = 5;
}

  

//DataGridView 编辑项输入
protected void Edit_Value(object sender, KeyPressEventArgs e)
{
DataGridViewTextBoxEditingControl control = (DataGridViewTextBoxEditingControl)sender; if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
{
e.Handled = true;//消除不合适字符
}
else if (Char.IsPunctuation(e.KeyChar))
{
if (e.KeyChar != '.' || control.Text.Length == 0)//小数点
{
e.Handled = true;
}
if (control.Text.LastIndexOf('.') != -1)
{
e.Handled = true;
}
}
}

  

#region  输入

        //允许输入小数
public static void TextBox_Double_KeyPress(object sender, KeyPressEventArgs e)
{
TextBox tb = (TextBox)sender;
if (tb == null)
{
e.Handled = true;//消除不合适字符
return;
}
if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
{
e.Handled = true;//消除不合适字符
}
else if (Char.IsPunctuation(e.KeyChar))
{
if (e.KeyChar != '.' || tb.Text.Length == )//小数点
{
e.Handled = true;
}
if (tb.Text.LastIndexOf('.') != -)
{
e.Handled = true;
}
}
} //只能输入整数
public static void Number_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != '\b')//这是允许输入退格键
{
if ((e.KeyChar < '') || (e.KeyChar > ''))//这是允许输入0-9数字
{
e.Handled = true;
}
}
} //DataGridView 编辑项输入
public static void DataGridView_Edit_Value(object sender, KeyPressEventArgs e)
{
DataGridViewTextBoxEditingControl control = (DataGridViewTextBoxEditingControl)sender; if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
{
e.Handled = true;//消除不合适字符
}
else if (Char.IsPunctuation(e.KeyChar))
{
if (e.KeyChar != '.' || control.Text.Length == )//小数点
{
e.Handled = true;
}
if (control.Text.LastIndexOf('.') != -)
{
e.Handled = true;
}
}
} #endregion

DataGirdView 编辑项时的验证的更多相关文章

  1. thinkphp5 编辑时 唯一验证 解决办法

    若定义了相关的验证规则,如: namespace app\seller\validate; use think\Validate; class Goodsmtag extends Validate { ...

  2. [转]使用Maven添加依赖项时(Add Dependency)时,没有提示项目可用,并且在Console中,输出: Unable to update index for central|http://repo1.maven.org/maven2 。

    使用Maven添加依赖项时(Add Dependency)时,没有提示项目可用,并且在Console中,输出: Unable to update index for central|http://re ...

  3. vs切换当前编辑文件时自动定位目录树

    在编辑区,切换当前编辑文件时(单击.cpp或.h文件选项卡),"解决方案资源管理器"目录树会自动定位当前编辑的文件,并以灰色标识,当一个解决方案中的工程数目数目很多,每个工程下面又 ...

  4. 解决Eclipse编辑JavaScript时卡的问题

    eclipse在开发JavaEE项目时容易卡,特别是在编辑JavaScript时,经过网上各种搜索,综合整理一下,对自己的eclipse设置之后,结果不在出现卡的问题了. 原文地址:http://bl ...

  5. WPF学习笔记(8):DataGrid单元格数字为空时避免验证问题的解决

    原文:WPF学习笔记(8):DataGrid单元格数字为空时避免验证问题的解决 如下图,在凭证编辑窗体中,有的单元格不需要数字,但如果录入数字后再删除,会触发数字验证,单元格显示红色框线,导致不能执行 ...

  6. VS新建工程或者新建项时 出现未定义标识符号

    VS新建工程或者新建项时 出现未定义标识符号,编译之后不影响运行,但是看着很不舒服,影响效率. 解决办法:属性--->VC++目录-->包含目录-->编辑,将自己所用QT的inclu ...

  7. 扩展BindingList,防止增加、删除项时自动更新界面而不出现“跨线程操作界面控件 corss thread operation”异常

    在做界面程序时,常常需要一些数据类,界面元素通过绑定等方式显示出数据,然而由于UI线程不是线程安全的,一般都需要通过Invoke等方式来调用界面控件.但对于数据绑定bindingList而言,没法响应 ...

  8. [转]jQuery.validate插件在失去焦点时执行验证代码

    转:http://my.oschina.net/enyo/blog/311566 关于 jquery.validate.js 表单验证插件如何在失去焦点时做验证.看手册后发现默认是在表单提交时执行验证 ...

  9. 未能加载文件或程序集“Enyim.Caching”或它的某一个依赖项。未能验证强名称签名

    from:http://www.mzwu.com/article.asp?id=3741 itHub下载Enyim项目,编译后引用程序运行出错: 引用内容 未能加载文件或程序集“Enyim.Cachi ...

随机推荐

  1. Javascript获取不重复的随机数值

    /** * 获取不重复随机数 * @param integer start 随机数最小值 * @param integer end 随机数最大值 * @param integer size 随机数获取 ...

  2. Effective JavaScript :第一章

    第一章 一.严格模式与非严格模式 1.在程序中启用严格模式的方式是在程序的最开始增加一个特定的字符串字面量: ‘use strict’ 同样可以在函数体的开始处加入这句指令以启用该函数的严格模式. f ...

  3. file_zilla 通过key连接远程服务器

    file_zilla 通过key连接 01 在putty中 ifconfig -a 查看当前网站ip02 文件-站点管理器--新建站点---主机ip 端口2203协议 SFTP 就是SSH协议04登录 ...

  4. 转Rollback后undo到底做了些什么?

    转自:http://biancheng.dnbcw.info/oracle/309191.html Rollback后undo到底做了些什么? 从概念上讲,undo正好与redo相对.当你对数据执行修 ...

  5. Java 散知识

    1.final关键字的用法: 1. final关键字修饰一个基本类型的变量时,该变量不能重新赋值,第一次的值为最终的. 2. fianl关键字修饰一个引用类型变量时,该变量不能重新指向新的对象. 3. ...

  6. 大数据阶乘(The factorial of large data)

    题目描述 Description 阶乘是计算中的基础运算,虽然规则简单,但是位数太多了,也难免会出错.现在的问题是:给定任意位数(long long类型)的一个数,求它的阶乘,请给出正确结果.为提高速 ...

  7. erlang dets

    1.dets表包含set.bag.和duplicate bag 2.dets:open_file(TableName,Options)创建或打开表 3.Options 1){auto_save,Int ...

  8. Html加载swf 兼容IE8 (含以下)显示

    嵌入参数说明: 1,AllowScriptAccess  参数: sameDomain:仅当 SWF 文件和网页位于同一域中时才允许执行外出脚本访问.这是 AVM2 内容的默认值----播放网络视频, ...

  9. mysql表备份及还原

    备份 导出数据库所有表结构 ? 1 mysqldump -uroot -ppassword -d dbname > db.sql 导出数据库某个表结构 ? 1 mysqldump -uroot ...

  10. 2016-11-10linux

    ---恢复内容开始---  新建用户natasha,uid为88,gid为6,备注信息为"master"   修改natasha用户的家目录为/Natasha    查看用户信息配 ...