Mohamed Said

Mohamed Said

  • NA
  • 58
  • 5.9k

How to validate and focus each text box alone

Nov 9 2017 8:48 AM
- i have two Texbox (1)Name, (2)Code. i want to validate each textbox alone but the code didn't work. every time show the first messagebox when i repeat Name OR Code 
 
Code:- 
 
if (dt.Rows.Count > 0 || dt2.Rows.Count > 0)
{
  if (dt.Rows.Count > 0)
  {
    MessageBox.Show("this Name was inserted !", "Warning ", MessageBoxButtons.OK,          MessageBoxIcon.Warning);
    txt_Name.Focus();
    txt_Name.SelectionStart = 0;
    txt_Name.SelectionLength = txt_Name.TextLength;
    return;
  }
  else if (dt2.Rows.Count > 0)
  {
    MessageBox.Show("That Code was inserted !", "Warning ", MessageBoxButtons.OK,          MessageBoxIcon.Warning);
    txt_Code.Focus();
    txt_Code.SelectionStart = 0;
    txt_Code.SelectionLength = txt_Code.TextLength;
    return;
  }
}

Answers (1)