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* ...
随机推荐
- HDU 2473 Junk-Mail Filter(并查集的删除操作)
题目地址:pid=2473">HDU 2473 这题曾经碰到过,没做出来. .如今又做了做,还是没做出来. ... 这题涉及到并查集的删除操作.想到了设一个虚节点,可是我把虚节点设为了 ...
- Android中RelativeLayout各个属性及其含义
android:layout_above="@id/xxx" --将控件置于给定ID控件之上android:layout_below="@id/xxx" - ...
- Android Apk包下查看 sha1
用keytool工具查看sha1,格式如下:keytool -printcert -file Urovo.RSA文件路径(APK解压后在Meta-INF文件夹下)
- PageHelper
https://pagehelper.github.io/ Mybatis分页插件PageHelper简单使用 SpringBoot之分页PageHelper
- API自动化测试利器——Postman
自从开始做API开发之后,我就在寻找合适的API测试工具.一开始不是很想用Chrome扩展,用的WizTools的工具,后来试过一次Postman之后就停不下来了,还买了付费的Jetpacks.推出T ...
- Eclipse打jar包的方法
1.准备主清单文件 “MANIFEST.MF” Manifest-Version: 1.0 Class-Path: lib/commons-codec.jar lib/commons-httpclie ...
- 九度OJ 1067:n的阶乘 (数字特性)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6476 解决:2471 题目描述: 输入一个整数n,输出n的阶乘 输入: 一个整数n(1<=n<=20) 输出: n的阶乘 样例 ...
- No provisioned iOS devices are available with a compatible iOS version. Connect an iOS device with a
No provisioned iOS devices are available with a compatible iOS version. Connect an iOS device with a ...
- [容易]在O(1)时间复杂度删除链表节点
题目来源:http://www.lintcode.com/zh-cn/problem/delete-node-in-the-middle-of-singly-linked-list/
- JAVA Exception处理
原文地址:http://blog.csdn.net/hguisu/article/details/6155636 1. 引子 try…catch…finally恐怕是大家再熟悉不过的语句了,而且感觉用 ...