C# DataGridView的單元格中只能輸入數字
控件類型:DataGridView
控件名稱:dgvGift_Condition
裏面用到的:IsNumeric、NotePastText、RestoreText 等請參見 前一日志“TextBox中只能輸入數字”。
下面例子中 dgvGift_Condition中 第2列和第4列 只能輸入數字
private DataGridViewTextBoxEditingControl EditingControl = new DataGridViewTextBoxEditingControl();
private void dgvGift_Condition_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (this.dgvGift_Condition.CurrentCell.ColumnIndex == 1 || this.dgvGift_Condition.CurrentCell.ColumnIndex == 3)
{
EditingControl = (DataGridViewTextBoxEditingControl)(e.Control);
EditingControl.KeyPress += new KeyPressEventHandler(EditingControl_KeyPress);
EditingControl.TextChanged += new EventHandler(EditingControl_TextChanged);
}
}
void EditingControl_TextChanged(object sender, EventArgs e)
{
if (this.IsNumeric(this.EditingControl.Text, true, false))
{
this.NotePastText(this.EditingControl, ref PastText);
}
else
{
this.RestoreText(this.EditingControl, PastText);
}
}
void EditingControl_KeyPress(object sender, KeyPressEventArgs e)
{
this.CheckKeyIn(e, false);
}
private void dgvGift_Condition_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
if (e.ColumnIndex == 1 || e.ColumnIndex == 3)
{
TextBox tb = new TextBox();
if (this.dgvGift_Condition.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
{
tb.Text = "";
}
else
{
tb.Text = this.dgvGift_Condition.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
}
this.NotePastText(tb, ref PastText);
}
}
private void dgvGift_Condition_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
EditingControl.KeyPress -= EditingControl_KeyPress;
EditingControl.TextChanged -= EditingControl_TextChanged;
}
C# DataGridView的單元格中只能輸入數字的更多相关文章
- android ios 只能輸入數字 不能輸入小數點的 函數 cordova
andriod function numericsonly(ob) { var invalidChars = /[^0-9]/gi if (invalidChars.test(ob.value)) { ...
- Winform DataGridView列的单元格中动态添加图片和文字
先上图在说,第二列中图片和文字的样式 1.需要重写DataGridViewTextBoxColumn,新建类TextAndImageColumn.cs using System; using Syst ...
- DataGrid 獲取 制定 row Col 單元格
public static class DataGridHelper { /// <summary> /// Gets the v ...
- WinForm中DataGridView复制选中单元格内容解决方案
WinForm中DataGridView鼠标选中单元格内容复制方案 1.CTR+C快捷键复制 前提:该控件ClipboardCopyMode属性设置值非Disable: 2.鼠标框选,自定义代码实现复 ...
- 设置DataGridView的某个单元格为ComboBox
怎么将DataGridView的 某个单元格设为ComboBox的样式而不是整列都改变样式? 1.最简单的方法:利用DataGridView提供的DataGridViewComboBoxCell. 写 ...
- ASP.NET MVC 單元測試系列
ASP.NET MVC 單元測試系列 (7):Visual Studio Unit Test 透過 Visual Studio 裡的整合開發環境 (IDE) 結合單元測試開發是再便利不過的了,在 Vi ...
- POI如何自动调整Excel单元格中字体的大小
问题 目的是要将Excel中的文字全部显示出来,可以设置对齐格式为[缩小字体填充],但是这样的话只能展示出一行数据,字体会变得很小.还有一种办法,设置对齐格式为[自动换行],然后让单元格中的字体自动调 ...
- 控制input中只能输入固定格式内容
onkeyup 事件会在键盘按键被松开时发生,onafterpaste 是粘贴触发,没有这个事件用onblur吧,失去焦点时发生输入完,点其他地方就会执行. <html lang="e ...
- 当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式。
当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式.比如 select * from T_Employee where FNumber not in ( select top 5* ...
随机推荐
- c 字符串 函数
c编辑 strcpy 原型:extern char *strcpy(char *dest,char *src); 用法:#include <string.h> 功能:把src所指由NUL结 ...
- python 基础1.1--windows/linux 下安装python
一.windows下安装python 1>windows上python后缀是.msi的,下载下来后,直接双击运行.会在c盘生成python.exe的文件,把python.exe的文件加入到win ...
- 公网yum 源地址
1. centos5.* 公网yum 源地址 [root@web ~]# cd /etc/yum.repos.d/[root@web yum.repos.d]# wget -O /etc/yum.r ...
- cf-341C Iahub and Permutations
C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Moving Computation is Cheaper than Moving Data
https://hadoop.apache.org/docs/r1.2.1/hdfs_design.html Introduction The Hadoop Distributed File Syst ...
- Thinkphp2.2 config.inc.php常用配置
CHECK_FILE_CASE -- windows环境下面的严格检查大小写. /* 项目设定 */ 'APP_DEBUG' => false, // 是否开启调试模式 'AP ...
- TCP黏包问题
什么是黏包?什么情况下会出现黏包的情况?该如何避免黏包的情况? 首先来看一个例子 #服务端 import time from socket import * server = socket(AF_IN ...
- Gemini.Workflow 双子工作流入门教程三:定义流程:流程节点、迁移条件参数配置
简介: Gemini.Workflow 双子工作流,是一套功能强大,使用简单的工作流,简称双子流,目前配套集成在Aries框架中. 下面介绍本篇教程:定义流程:流程节点.迁移条件参数配置. 一.普通节 ...
- [2018-11-27]2018年12月1日宁波dotnet社区线下活动
离上次活动,转眼又过了一个月,幸得各路大神支持,于本周六(12月1日),宁波dotnet社区的线下分享活动又来啦! 活动嘉宾及主题 董斌辉 2015-2019年微软全球最有价值专家(.NET方向) 2 ...
- haproxy 官方文档查看
http://cbonte.github.io/haproxy-dconv/1.5/configuration.html#reqrep http://www.ttlsa.com/linux/hapro ...