C# 在文本框中仅输入十进制数字“否”

C# 在文本框中仅输入十进制数字“否”,c#,C#,我有一个DataGridView,我只想验证单元格中应该输入的十进制No 我正在使用窗口窗体,并在DataGridView中动态生成列 请帮助我使用CellValidating事件: private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (e.ColumnIndex == theColumnToValidate.Index) {

我有一个DataGridView,我只想验证单元格中应该输入的十进制No 我正在使用窗口窗体,并在DataGridView中动态生成列


请帮助我

使用
CellValidating
事件:

private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
    if (e.ColumnIndex == theColumnToValidate.Index)
    {
        decimal d;
        if (!decimal.TryParse(e.FormattedValue.ToString(), out d))
        {
            MessageBox.Show("Please enter a decimal number");
            e.Cancel = true;
        }
    }
}

嗨,thomas,我正在处理KeyPress事件并完成了它,但问题是,如果(Char.isleter(e.KeyChar)){e.Handled=true;}键入Ctrl+V以击败此类代码,我无法仅在点(.)上进行验证。验证是正确的。