//回车切换焦点方法,只需在界面设置控件的TabIndex即可,以后用

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((!(ActiveControl is Button)) && (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Enter))
            {
                if (keyData == Keys.Enter)
                {
                    System.Windows.Forms.SendKeys.Send("{TAB}");
                    return true;
                }
                if (keyData == Keys.Down)
                    System.Windows.Forms.SendKeys.Send("{TAB}");
                else
                    SendKeys.Send("+{Tab}");
                return true;
            }
            else
                return base.ProcessCmdKey(ref msg, keyData);
        }

  

     // GridView中回车横向移焦点,保存好些方法

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            enterkey = false;
            if (keyData == Keys.Enter)
            {
                if (this.dataGridView1.IsCurrentCellInEditMode)
                {
                    enterkey = true;
                    if (this.dataGridView1.CurrentCell.ColumnIndex < this.dataGridView1.ColumnCount - 1)
                    {
                        if (this.dataGridView1.CurrentCell.ColumnIndex == 5)
                        {
                            DataRow row = dt.NewRow();
                            row["ID"] = dt.Rows.Count + 1;
                            row["QrCode"] = "";
                            row["JiuKuanName"] = "";
                            row["ShuLiang"] = "0";
                            row["DanJia"] = "0";
                            row["JinE"] = "0";
                            dt.Rows.Add(row);//添加新行 
                            this.dataGridView1.DataSource = dt;
                            dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[2];
                            return false; ;
                        }
                        else
                        {
                            this.dataGridView1.CurrentCell = this.dataGridView1[this.dataGridView1.CurrentCell.ColumnIndex + 3,this.dataGridView1.CurrentCell.RowIndex];

                        }
                    }
                }
            }

            return base.ProcessCmdKey(ref msg, keyData);

        }

相关文章:

  • 2020-11-14
  • 2021-12-29
  • 2021-11-23
  • 2021-09-13
  • 2021-09-07
  • 2021-11-06
  • 2021-12-06
  • 2021-11-26
猜你喜欢
  • 2021-08-01
  • 2018-05-18
  • 2017-12-12
  • 2021-08-21
  • 2021-12-09
  • 2021-11-30
  • 2020-11-14
  • 2021-11-30
相关资源
相似解决方案