首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

DatagridView 怎样按下Enter 或 UP 或 Down 到 下一行,该如何处理

2012-05-16 
DatagridView 怎样按下Enter 或 UP 或 Down 到 下一行DatagridView 怎样按下Enter 或 UP 或 Down 到 下一

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

热点排行