Hi Friends,
Encounter another interesting problem of practical event. I have used FORM KEYDOWN event to navigate the cursor and on the Primary Key TextBox I tried to validate the input after ENTER was pressed it does not work.
Here are the coding
---------------------------------
Primay key TextBox
Encounter another interesting problem of practical event. I have used FORM KEYDOWN event to navigate the cursor and on the Primary Key TextBox I tried to validate the input after ENTER was pressed it does not work.
Here are the coding
Code:
private void FrmCustomerRef_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { this.Close(); } //navigate textbox if (e.KeyCode == Keys.Enter) { ProcessTabKey(true); } }
---------------------------------
Primay key TextBox
Code:
private void txtCustID_Enter(object sender, EventArgs e) { //check for duplicate CustomerID int intReturn = 0; try { string strSql = "Select * from Customers Where CustomerID = '" + this.txtCustID.Text + "'"; sqlconn = new SqlConnection(connstr); sqlcmd = new SqlCommand(strSql, sqlconn); sqlconn.Open(); intReturn = Convert.ToInt32(sqlcmd.ExecuteScalar()); if (intReturn > 0) // record duplicate { string txtMsg = "This CustomerID : " + txtCustID.Text + "\n" + " belongs to another Customer "; MessageBox.Show(txtMsg, "Duplicate CustomerID", MessageBoxButtons.OK); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
Comment