Validate Email Id in Datagridview cell
How to validate datagridview cell for valid email id. in C#.net winform
1 Answer
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
Shankar MRank #874 · 2.5K reputationPosted Apr 26, 2013, 7:58 PM EDT
You can validate the E-mail Id in Datagridview's CellValidatingEvent Something like this,
Presume that dgv is the name of the DataGridview and MailId is one of the column of Datagridview.
string HeaderText = dgv.Columns[e.ColumnIndex].HeaderText;
This is to get the header Text of the Column, to check that we are in the E-mail id column.
if (!HeaderText.Equals("MailId")) return;
Abort validation if the cell is not MailId column.
if(string.IsNullOrEmpty(e.FormattedValue.ToString()))
{
MessageBox.Show("Please Enter the mail Id");
e.Cancel = true; // Will not allow us to Leave the cell until an non-empty string is entered.
}
You can also use Regular Expressions to validate that the E-Mail Id entered is Valid.