//------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 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("mb", "dgv", this); //mb=ManualBilling, dgv=DataGridView } } else if (int.Parse(keyVal) == 38) { KeyPressEvent kpe = new KeyPressEvent(); kpe.upArrow("mb", "dgv", this); } else if (int.Parse(keyVal) == 13) { if (dataGridView1.RowCount != 0) { KeyPressEvent kpe = new KeyPressEvent(); kpe.enterButton("mb", "dgv", this, billingform); } } else if (int.Parse(keyVal) == 27) { 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) < 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 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) { int qty = int.Parse(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[3].Value.ToString()); string code = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value.ToString(); 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.update_qty(this, qty, code); } 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); } }