C# datagridview 某列只能输入英文或数字
2013-10-25 11:42
218 查看
方法许多
正直表达式:"^[a-zA-Z0-9]+$"
这里不详细解答
自己用的方法是:
private void datagridview1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs
e)
{
TextBox innerTextBox;
if (e.Control is TextBox &&
datagridview1.CurrentCell.ColumnIndex==1) {
innerTextBox = e.Control as TextBox;
innerTextBox.KeyPress +=new KeyPressEventHandler(innerTextBox_KeyPress);
}
}
private void innerTextBox_KeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar != 8 && !char.IsNumber(e.KeyChar) && !char.IsLower(e.KeyChar) && !char.IsUpper(e.KeyChar))
{
e.Handled = true;
}
}
正直表达式:"^[a-zA-Z0-9]+$"
这里不详细解答
自己用的方法是:
private void datagridview1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs
e)
{
TextBox innerTextBox;
if (e.Control is TextBox &&
datagridview1.CurrentCell.ColumnIndex==1) {
innerTextBox = e.Control as TextBox;
innerTextBox.KeyPress +=new KeyPressEventHandler(innerTextBox_KeyPress);
}
}
private void innerTextBox_KeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar != 8 && !char.IsNumber(e.KeyChar) && !char.IsLower(e.KeyChar) && !char.IsUpper(e.KeyChar))
{
e.Handled = true;
}
}
相关文章推荐
- c#调用COM组件
- c#中虚函数的相关使用方法
- 浅析C# web访问mysql数据库-整理归纳总结
- C# IP地址与整数之间转换的具体方法
- C#实现的阴历阳历互相转化类实例
- C# 的关键字详细介绍
- c# 获得局域网主机列表实例
- C#中Convert.ToInt32()和int.Parse()的区别介绍
- C#面向对象特征的具体实现及作用详解
- 关于C# Math 处理奇进偶不进的实现代码
- c# 随机函数的使用详解
- c#之圆形无标题栏椭圆窗体的实现详解
- C#页面之间跳转功能的小结
- 浅析C# 基础语法的使用
- C#中将字符串转换为整型的三种解决方法总结
- 深入c# GDI+简单绘图的具体操作步骤(一)
- C#中英文混合字符串截取函数
- C# 面向对象的基本原则
- 使用C#开源文件实时监控工具Tail&TailUI介绍
- C# 正则判断一个数字的格式是否有逗号的代码