日期:2014-05-18  浏览次数:20905 次

DatagridView 怎样按下Enter 或 UP 或 Down 到 下一行
DatagridView 怎样按下Enter 或 UP 或 Down 到 下一行

如:
1 2 3

1 2 3  

当我在编辑 红色的记录时 按下Enter 或 UP 或 Down 移动到 这一列的下一个字段 也就是深红设的这个记录~~~~~~~~ 求高手解答啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

------解决方案--------------------
假设是TextBox类型列,msg.HWnd == this.dataGridView1.Handle这个条件根据需要取舍吧,在非编辑状态下回车会触发这个条件
C# code

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            bool result =false;
            Control c = Control.FromHandle(msg.HWnd);
            if (msg.HWnd == this.dataGridView1.Handle || (c is DataGridViewTextBoxEditingControl))
            {
                if (msg.WParam.ToInt32() == (int)Keys.Return)
                {
                    this.dataGridView1.CurrentCell = this.dataGridView1.CurrentRow.Cells[this.dataGridView1.CurrentCell.RowIndex + 1];
                    result = true;
                }
            }
            else
            {
                result = base.ProcessCmdKey(ref msg, keyData);
            }
            return result;
        }