日期:2014-05-18  浏览次数:20749 次

C#2005中的winForm中怎样让datagridview中的第一列只能输入数字
RT

------解决方案--------------------
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == 0)
{
MessageBox.Show( "检证是不是数字 ");
//if( "不是数字“)
// e.Cancel=true;
}
}
------解决方案--------------------
txt_ly() 的方法可行的。
------解决方案--------------------
using System.Text.RegularExpressions;
/// <summary>
/// 匹配正浮点数 大于0
/// </summary>
/// <param name= "strPlusFloatNumber "> </param>
/// <returns> </returns>
public static bool IsValidPlusFloatNoIncludeZero(string strPlusFloatNumber)
{
return Regex.IsMatch(strPlusFloatNumber, @ "^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$ ");
}
------解决方案--------------------
使用decimal.TryParse(text, out dec)来试着转一下,如果成功说明是数字类型的,否则是不正确的输入格式。