如何让在gridview中的单元格中按下回车健后,光标往后移,而不是往下移

解决方案 »

  1.   

    在datagrid的keyUp事件中添加代码        private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
            {
                char a = (char)Keys.Enter;
                if (e.KeyChar == a)
                {
                    int i = dataGridView1.CurrentCell.ColumnIndex;
                    if (i < dataGridView1.Columns.Count -1)
                    {
                        dataGridView1.CurrentCell = dataGridView1.CurrentRow.Cells[i + 1];
                    }
                }
            }
      

  2.   

    js控制下一个单元格获取焦点
    e.parentNode.nextSibling.focus();
    e代表当前单元格中的一个控件
      

  3.   

    写个类继承DataGridView      private class MyData : DataGridView
            {
                protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
                {
                    if (keyData == Keys.Enter)
                    {
                        System.Windows.Forms.SendKeys.Send("{tab}");
                        return true;
                    }
                    return base.ProcessCmdKey(ref msg, keyData);
                }
            }
    直接使用 MyData来做把.