예제 #1
0
        //------------------------------------------------------------------------------------------------------------------------------------------------------------------
        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);

            }

        }