开发者

Input only Decimal No in TextBOx

开发者 https://www.devze.com 2023-01-23 20:42 出处:网络
I have a DataGridView and I want to validate only Decimal No Should be input in a Cell i am u开发者_开发知识库sing window Form and i am generating Column in DataGridView Dynamically

I have a DataGridView and I want to validate only Decimal No Should be input in a Cell i am u开发者_开发知识库sing window Form and i am generating Column in DataGridView Dynamically

Plz help me


Use the CellValidating event:

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;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号