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. Linux安全检测常用方法

    一. 系统状态备份 主要是网络.服务.端口.进程等状态信息的备份工作 系统服务备份: chkconfig --list > services.log 进程备份: ps -ef > ps.l ...

  2. 第四节,Linux基础命令

    第四节,Linux基础命令 命令是系统操作员对系统传入的指令,传入指令后回车,系统接收到指令做出相应的行为 1.查看用户位于系统什么位置 [pmd]检查操作用户位于系统的什么位置 命令         ...

  3. java中字符串的操作

    //创建一个字符数组 char[] charArr = {'a','b','c','d','e','f','g'}; //创建一个字符串 String str = new String(charArr ...

  4. Date 和 SimpleDateFormat 类表示时间

    Date now=new Date(); // 使用format()方法将日期转换为指定格式的文本 SimpleDateFormat sdf1 = new SimpleDateFormat(" ...

  5. jQuery插件实现左右无缝轮播

    前段时间学习jQuery的时候,在网上找了个SuperSlide插件,做轮播图demo,感觉对于新人而言,还是挺容易上手的,代码量也少. 直接贴代码吧. 1.HTML <!DOCTYPE htm ...

  6. Dokan简介[转]

    1.      Dokan Library 简介 Dokan Library 帮助程序员在windows系统下轻松建立用户级文件系统,不需要写设备驱动,其与FUSE(Linux user mode f ...

  7. 【LeetCode】462. Minimum Moves to Equal Array Elements II

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  8. phpstrom 快捷使用方式

    file-settings--key map键映射-->collapse(代码折叠)---- ctrl (减减)2次全部折叠  (加加)2次全部展开 格式化代码  ctrl+alt+L 替换 c ...

  9. 模拟器SDK路径

    I'm guessing you already find it out, but just for the record: the UIKit.framework is available only ...

  10. MVC3+EF4.1学习系列(二)-------基础的增删改查和持久对象的生命周期变化

    上篇文章中 我们已经创建了EF4.1基于code first的例子  有了数据库 并初始化了一些数据  今天这里写基础的增删改查和持久对象的生命周期变化 学习下原文先把运行好的原图贴来上~~ 一.创建 ...