读书人

DatagridView 怎样按下Enter 或 UP 或

发布时间: 2012-05-16 23:40:10 作者: rapoo

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;        } 

读书人网 >C#

热点推荐