how to validate cell of datagridview enter only number in this cell
thanks,
Shailaja
How to enter only number in datagridview
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vidya Yadav22 reputationPosted Sep 25, 2009, 11:17 PM EDT
Use this code piece to solvw your problem.. Hope it will work
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = "";
double newInteger;
if (dataGridView1.Rows[e.RowIndex].IsNewRow)
{
return;
}
Vidya
if (!double.TryParse(e.FormattedValue.ToString(), out newInteger) || newInteger < 0)
e.Cancel = true;
dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer";
}
Roei BarRank #1,271 · 1.4K reputationPosted Sep 25, 2009, 11:34 PM EDT
Shailaja Mohite17 reputationPosted Sep 25, 2009, 11:37 PM EDT
Shailaja Mohite17 reputationPosted Sep 25, 2009, 11:41 PM EDT
How To Create Custome Columns In DatagridView in C# dotnet
thanks
Shailaja