• GridView中回车控制焦点以及DataGridView的焦点



         
        //回车切换焦点方法,只需在界面设置控件的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);

            }
  • 相关阅读:
    十一. 图形、图像与多媒体8.多媒体基础
    十一. 图形、图像与多媒体7.图像缓冲技术
    十一. 图形、图像与多媒体6.图像处理基础
    十一. 图形、图像与多媒体5.Graphics2D类的绘图方法
    十一. 图形、图像与多媒体4.Graphics类的绘图方法
    十一. 图形、图像与多媒体3.绘图模式
    十一. 图形、图像与多媒体2.设置字型和颜色
    十一. 图形、图像与多媒体1.绘图基础
    十. 图形界面(GUI)设计14.键盘事件
    linux 安装python3.6.10
  • 原文地址:https://www.cnblogs.com/chengpeng/p/2243711.html
Copyright © 2020-2023  润新知