rt

解决方案 »

  1.   

    private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
    {
        if (dataGridView1.CurrentRow.Index >= dataGridView1.RowCount) return;
        if (e.KeyCode == Keys.Tab)
        {
            DataGridViewCell cell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex + 1];
            dataGridView1.CurrentCell = cell;
            e.Handled = true;
        }
    }
      

  2.   

    从DataGridView派生一个新类,在新类中覆盖ProcessDialogKey方法protected override bool ProcessDialogKey(Keys keyData)
            {
                if (key == Keys.Tab)
                {
                    base.CurrentRow = base.Rows[base.CurrentRow.Index + 1];
                    return true;
                }
                return base.ProcessDialogKey(keyData);
            }
      

  3.   

    以上两种方法看似都可行,不过我没去试
    提醒一下就是:Index + 1时先检查一下看是不是最后一行了.
      

  4.   

     protected override bool ProcessCmdKey(ref Message msg, Keys KeyData)
            {
                if (KeyData == Keys.tab)
                {
                    SendKeys.Send("{Enter}");
                    return true;
                }
                return base.ProcessCmdKey(ref  msg, KeyData);
            }
      

  5.   


    private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Tab)
        {
            SendKeys.Send("{Enter}");
            e.Handled = true;
        }
    }
      

  6.   


    你好,你的方法可行,偷梁换柱了一下,你是想按TAB时是想ENTER的功能,但是我按ENTER时,又触发了另外 一个事件,所以此方法不可行,
      

  7.   


    改为
    dataGridView1.CurrentRow.Index>= dataGridView1.RowCount-1
      

  8.   


    你好,结果是正确的,但是如何能完善一下呢:
    就是能用TAB和SHIF+TAB进行各条记录之间切换,目前第一行切换不到,而且最后一行不是记录间切换,而是最后一行单元格间切换,我想要整条切换,如何实现,谢谢!
      

  9.   

    if (e.KeyCode == Keys.Tab || e.KeyCode == Keys.Tab && e.Shift == true)
    {
        DataGridViewCell cell;
        if (dataGridView1.CurrentRow.Index < dataGridView1.RowCount - 1)
            cell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex + 1];
        else cell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, 0];
        dataGridView1.CurrentCell = cell;
        e.Handled = true;
    }
      

  10.   


    private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
    {
      // 13楼代码
    }