如何判定datagridview中用户输入的字符类型 如何判定datagridview中用户输入的字符类型呢, 比如datagridview某一列,如何判断用户输入的是字符,还是数字呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { int i= 0.0; dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty; if(dataGridView1.Columns[e.ColumnIndex].DataPropertyName =="") { if(!int.TryParse(e.FormattedValue.ToString(),out s) ||s <0) { dataGridView1.Rows[e.RowIndex].ErrorText = "输入有误!"; e.Cancel = true; } } } private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty; } int i= 0.0; dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty; if(dataGridView1.Columns[e.ColumnIndex].DataPropertyName =="") { if(!int.TryParse(e.FormattedValue.ToString(),out i)||i <0) { dataGridView1.Rows[e.RowIndex].ErrorText="输入有误!"; e.Cancel = true; } } this.KeyPreview = true;private void Form1_KeyPress(object sender, KeyPressEventArgs e){ if (char.IsDigit(e.KeyChar)) MessageBox.Show("数字"); else if (char.IsLetter(e.KeyChar)) MessageBox.Show("字母"); else if (char.IsWhiteSpace(e.KeyChar)) MessageBox.Show("空"); // ...} int i= 0.0; 这样子一句肯定会报错的, 这种方式验证,对于小数部分好像会失效. 正则控件是什么英文啊,我找不到呀,另外 if (char.IsDigit(e.KeyChar)) MessageBox.Show("数字"); 只能验证整数呀, 我的目的是可以验证小数与整数, 该如何改呢, if (char.IsDigit(e.KeyChar)) MessageBox.Show("数字"); 只能检查整数呀,我打一个小数点都不行。 Application Reference 是什么东东,他属于b/s,c/s,还是什么? 字符串处理问题 有没有能显示多列的listbox或是其他能显示多列的表 我的C1FlexGrd 控件为什么看不到设计器? C#安装项目如何将MSI文件编译为exe文件 如何在DRAWING后的图片上加提示 需要模拟300个客户端向服务器端3000号端口交互消息,请问如何设计好?多少个线程合适? E8.net工作流源代码架构 bulk insert的运用问题 如何做个游戏左右压分平衡算法 请教一个获取程序版本的问题 实现对.jpg进行屏蔽了 分享下
{
int i= 0.0;
dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty;
if(dataGridView1.Columns[e.ColumnIndex].DataPropertyName =="")
{
if(!int.TryParse(e.FormattedValue.ToString(),out s) ||s <0)
{
dataGridView1.Rows[e.RowIndex].ErrorText = "输入有误!";
e.Cancel = true;
}
}
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty;
}
dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty;
if(dataGridView1.Columns[e.ColumnIndex].DataPropertyName =="")
{
if(!int.TryParse(e.FormattedValue.ToString(),out i)||i <0)
{
dataGridView1.Rows[e.RowIndex].ErrorText="输入有误!";
e.Cancel = true;
}
}
{
if (char.IsDigit(e.KeyChar)) MessageBox.Show("数字");
else if (char.IsLetter(e.KeyChar)) MessageBox.Show("字母");
else if (char.IsWhiteSpace(e.KeyChar)) MessageBox.Show("空");
// ...
}
这样子一句肯定会报错的, 这种方式验证,对于小数部分好像会失效.