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* ...
随机推荐
- 018 nginx与第三模块整合[一致性哈希模块整合]
nginx第三方模块官网:http://wiki.nginx.org/HttpUpstreamConsistentHash nginx第三方模块下载地址:https://github.com/repl ...
- ASP.NET MVC 4 技术讲解
ASP.NET MVC 相关的社群与讨论区 Routing 与 ASP.NET MVC 生命周期 Model相关技术 Controller相关技术 View数据呈现相关技术 Area区域相关技术 AS ...
- Swift实战(一): 剪子包袱锤ios应用
来自十奶的大作业教学视频. http://www.swiftv.cn/course/ic2tqzob 主要了解了MVC模型. 首先是View,通过设计mainstoryboard构建UI界面,主要靠拖 ...
- 微信小程序设置控件权重
项目中最常用的两种布局方式,水平布局和垂直布局,在微信小程序中实现起来也比较简单. 1.横向水平布局: 实现水平布局,需要四个view容器组件,其中一个是父容器.如下: & ...
- Python 深入剖析SocketServer模块(二)(V2.7.11)
五.Mix-In混合类 昨天介绍了BaseServer和BaseRequestHandler两个基类,它们只用与派生,所以贴了它们派生的子类代码. 今天介绍两个混合类,ForkingMix-In 和 ...
- 【BZOJ2406】矩阵 二分+有上下界的可行流
[BZOJ2406]矩阵 Description Input 第一行两个数n.m,表示矩阵的大小. 接下来n行,每行m列,描述矩阵A. 最后一行两个数L,R. Output 第一行,输出最小的答案: ...
- Asp.Net中判断是否登录,及是否有权限?
不需要在每个页面都做判段, 方法一:只需要做以下处理即可 using System; using System.Collections.Generic; using System.Linq; usin ...
- opencv的x64库的版本和vs的版本的对应关系
1 关于vs的版本 visual studio是一个集成开发环境,而vc++是一个c++的compiler,vc++有一个版本和一个版本号,vs也有一个版本,它们的对应关系如下: MSVC++ 4.x ...
- Java for LeetCode 088 Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. 解题思路一: ...
- 《C prime plus (第五版)》 ---第11章 字符串和字符串函数
11-1:字符串表示和字符串I/O 1.首先先通过一个整体的例子来初步了解建立,读入和输出字符串的几种方式. #include<stdio.h> #define MSG "你一定 ...