zoukankan      html  css  js  c++  java
  • 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);

            }
  • 相关阅读:
    WebView用法与JS交互(2) 响应webview中的图片点击事件
    出栈序列(栈和队列)
    Log Files
    Mr. Frog’s Game
    Comparison of Android versions
    Linearization of the kernel functions in SVM
    Game of Nuts
    Easy Summation
    Automatic Judge
    Coprime Sequence
  • 原文地址:https://www.cnblogs.com/chengpeng/p/2243711.html
Copyright © 2011-2022 走看看