//------------------------------------------------------------------------------------------------------------------------------------------------------------------ public void dataGridView1_KeyDown(object sender, KeyEventArgs e) { try { string keyVal; keyVal = e.KeyValue.ToString(); if (int.Parse(keyVal) == 40) { if (dataGridView1.RowCount != 0 || dataGridView1.RowCount != 1) { KeyPressEvent kpe = new KeyPressEvent(); kpe.downArrow("bf", "dgv", this); //mb=ManualBilling, dgv=DataGridView } } else if (int.Parse(keyVal) == 38) { KeyPressEvent kpe = new KeyPressEvent(); kpe.upArrow("bf", "dgv", this); } else if (int.Parse(keyVal) == 13) { KeyPressEvent kpe = new KeyPressEvent(); kpe.enterButton("bf", "dgv", this); } else if (int.Parse(keyVal) == 27) { dataGridView1.Rows[0].Selected = true; dataGridView1.CurrentCell = dataGridView1[0, 0]; ActiveControl = txtBoxDescription; // focus on Description textbox dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control txtBoxDescription.Select(txtBoxDescription.Text.Length, 0); //move cursor into the end of text in the textbox } else if (int.Parse(keyVal) == 46) { dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex); if (dataGridView1.RowCount == 0) { ActiveControl = txtBoxDescription; // focus on Description textbox dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control txtBoxDescription.Select(txtBoxDescription.Text.Length, 0); //move cursor into the end of text in the textbox } else { dataGridView1.Rows[0].Selected = true; dataGridView1.CurrentCell = dataGridView1[0, 0]; ActiveControl = txtBoxDescription; // focus on Description textbox dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control txtBoxDescription.Select(txtBoxDescription.Text.Length, 0); //move cursor into the end of text in the textbox } BillGeneration bg = new BillGeneration(); bg.total(this); } else { if (int.Parse(keyVal) < 65 && int.Parse(keyVal) > 105 && int.Parse(keyVal) != 32) { SystemSounds.Hand.Play(); } } } catch (Exception exc) { MessageBox.Show("Error Occured, Please Try Again, " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ public void textBox2_KeyDown(object sender, KeyEventArgs e) { try { string keyVal = e.KeyValue.ToString(); if (int.Parse(keyVal) > 95 && int.Parse(keyVal) < 106) { string key = e.KeyCode.ToString(); key = key.Substring(6, key.Length - 6); textBox2.ReadOnly = false; if (textBox2.Text.Length < 4) { textBox2.Text = textBox2.Text + key; } textBox2.Select(textBox2.Text.Length, 0); textBox2.ReadOnly = true; } else if (int.Parse(keyVal) == 8) //validate BackSpace--------------------------------------------------------------- { if (textBox2.Text.Length != 0) { textBox2.Text = textBox2.Text.Substring(0, textBox2.Text.Length - 1); //remove last character from the text of the textbox textBox2.Select(textBox2.Text.Length, 0); //move cursor into the end of text in the textbox } else { SystemSounds.Hand.Play(); } } else if (int.Parse(keyVal) == 37 || int.Parse(keyVal) == 39) { } else if (int.Parse(keyVal) == 13) { KeyPressEvent kpe = new KeyPressEvent(); kpe.enterButton("bf", "qty", this); } else { SystemSounds.Hand.Play(); } } catch (Exception exc) { MessageBox.Show("Error Occured, Please Try Again, " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }