• 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);

            }
  • 相关阅读:
    Mysql入门-对表数据的增删改查
    Mysql教程-自动备份数据库
    前端基础教程-jQuery EasyUI 的EasyLoader实例
    html上标与下标应用
    git使用教程
    retrofit2.0缓存设置
    android 模拟用户点击事件
    power designer 16.5 生成mysql8.0注释
    Navicat连接Mysql8.0.11出现1251错误
    mongodb 安装配置及简单使用
  • 原文地址:https://www.cnblogs.com/chengpeng/p/2243711.html
Copyright © 2020-2023  润新知