本人做的是vb.net 大伙给c#的代码也可以
就是 winform上有 2个一样的 gridview
一共5列 前面2列是不可以输入的 后面3列是可以输入的
当 按下 enter 的时候 焦点在后面3列移动
从左到右 从上到下 也就是从 第一gridview的第一行第三列开
一直移动到第二gridview的最后一行最后一列 如此循环
还有个问题请教下
比如有个gridview有6行 最后一行跟最后第二行取得的
gridview.CurrentCell.RowIndex 怎么都是5? 
而且gridview.CurrentCell.RowIndex从1开始的有点奇怪
gridview.CurrentCell.ColumnIndex 从0开始都正确的

解决方案 »

  1.   

    和数据源绑定是不是用的Dataview
      

  2.   

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

  3.   

    问题1没理解
    问题2
        你绑定的数据源有问题或者是DataGridView某些设置有问题把
      

  4.   

    http://topic.csdn.net/u/20090922/11/94b215f4-4b10-4172-936c-656532bd0a3b.html
      

  5.   

    libinguest (风的足迹) 
    你的这个方法 之前也用过
    焦点会5个列都跑的 
      

  6.   

    也就是 不可输入的cell
    焦点也能上去的 
      

  7.   


    你代码是加上判断,如果此列是只读,那么就再次发送SendKeys.Send("{Enter}");
      

  8.   

    这个没做过
    你看这样的思路可不可以
    当你按enter键就做个判断,如果列索引小于4,就把焦点后移一个cell,否则移到下一行的列索引2
      

  9.   

    C# codeprivate void dataGridView1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Tab)
        {
            SendKeys.Send("{Enter}");
            e.Handled = true;
        }
    }
    好像 完全不行么 你试过吗
      

  10.   

        if (e.KeyCode == Keys.Enter
        { 
            SendKeys.Send("{Tab}"); 
            e.Handled = true; 
        } 
      

  11.   

    我的意思 按下 enter的时候当 tab用
    但是 又要跳过  前面2个不能输入的列
      

  12.   

          if (e.KeyCode == Keys.Enter) 
        { 
            SendKeys.Send("{Tab}"); 
            e.Handled = true; 
        } 
    你的方法跟我下面方法是一样  我重写了 就是tab的效果 但要跳过
    前面2列不能输入的 还是没有解决
     Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
        ByVal keyData As System.Windows.Forms.Keys) As Boolean        Select Case keyData
                Case Keys.Enter
                        SendKeys.Send("{Tab}")
                    Return True
            End Select        MyBase.ProcessCmdKey(msg, keyData)        Return False    End Function
      

  13.   


        Private Sub gl001_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles gl001.KeyPress        If gl001.CurrentCell.ColumnIndex < 4 Then
                gl001.CurrentCell = gl001(gl001.CurrentCell.ColumnIndex + 1, gl001.CurrentCell.RowIndex - 1)
                Return
            ElseIf gl001.CurrentCell.RowIndex < gl001.RowCount And gl001.CurrentCell.ColumnIndex = 4 Then
                gl001.CurrentCell = gl001(2, gl001.CurrentCell.RowIndex)
                Return
            ElseIf gl001.CurrentCell.RowIndex = gl001.RowCount - 1 And gl001.CurrentCell.ColumnIndex = 2 Then
                gl001.CurrentCell = gl001(2, 1)
                Return
            End If    End Sub
    还有这个方法 但是gridview.CurrentCell.RowIndex这个最后行出问题了
      

  14.   

    焦点如果碰到只读列再次发送,你需要用到两个事件,一个按下,一个放开事件.用下面的代码再试一下
    我测试没有问题.
            private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (dataGridView1.Columns[this.dataGridView1.CurrentCell.ColumnIndex].ReadOnly)
                {
                    SendKeys.Send("{Tab}");
                    e.Handled = true;
                }
            }        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyValue == 13)
                {
                    if (dataGridView1.Columns[this.dataGridView1.CurrentCell.ColumnIndex].ReadOnly)
                    {
                        SendKeys.Send("{Tab}");
                        e.Handled = true;
                    }
                    else
                    {
                        SendKeys.Send("{Tab}");
                        e.Handled = true;
                    }
                }
            }
      

  15.   

    最终事件和代码:        private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (dataGridView1.Columns[this.dataGridView1.CurrentCell.ColumnIndex].ReadOnly)
                {
                    SendKeys.Send("{Tab}");
                    e.Handled = true;
                }
            }        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyValue == 13)
                {
                    SendKeys.Send("{Tab}");
                    e.Handled = true;
                }
            }
      

  16.   

    单个 GridView 没有什么问题
    2 个 都写上这2个事件的话
    还有个小问题 请教下  
    就是第一个运行完毕
    会跳到第二个GridView 的 第一行的第1个cell
    然后按enter 直接跳到 第一行的第4个cell(跳过了一个正确的cell)
    才开始就运行正常  
      

  17.   

    我是想跳到 下个GridView
    第一行不是只读的cell 也就是第一行第3列
    我这里取GridView的CurrentCell的坐标一直有点问题
    能再帮忙看看嘛
      

  18.   


    在你的第二个datagridview里也加上上面的两个事件及代码
      

  19.   

    都加了 我测试过了 你可以试试
    因为你第一个datagridview结束之后 没有指定跳到下个datagridview的具体位置
    所以默认焦点到了 第一个cell 
      

  20.   

    要知道第一个datagridview的焦点什么时候到达最后一个cell
    才写代码 把焦点设置到下个datagridview的具体位置 
      

  21.   

    只说一下怎么解决吧.第一:你把你的两个datagirdview的tab索引号设为相临的两个
    如datagridview1为3,那么第二个为4第二:在你的第二个datagridview获得焦点事件里写上判断代码.
      

  22.   

    第一点没有什么问题第二点 第二个datagridview获得焦点的事件 我认为还是只能在
    第一个datagridview的KeyPress的事件里面 如果认为这个是
    最后一个cell 就代码设置使焦点跳到
    第二个datagridview的可输入的第一个cell这是我的思路了 关键问题还是我这里第一个datagridview取cell坐标有问题
    所以想请你看一下
      

  23.   

    关键问题还是我这里第一个datagridview取cell坐标有问题???我一直都想不通这个和坐标有什么关系.
      

  24.   

    第二:在你的第二个datagridview获得焦点事件里写上判断代码.
    请问这个获得焦点的事件在哪里?
      

  25.   


    就是控件为窗体的活动控件时.        private void dataGridView1_Enter(object sender, EventArgs e)
            {        }
      

  26.   

    你不断的问,CSDN不断的回,这样的问题何时了.
    你的思路要清晰,答的我都有点晕头转向了.