private DataGridViewTextBoxEditingControl EditCell;        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            EditCell = (DataGridViewTextBoxEditingControl)e.Control;
            EditCell.SelectAll();
            EditCell.KeyPress += new KeyPressEventHandler(Cells_KeyPress);
        }        void Cells_KeyPress(object sender, KeyPressEventArgs e)
        {           
            
            if (Char.IsNumber(e.KeyChar) )//判断是不是数字
            {
                
                
                e.Handled = true;
            }           
            string key = e.KeyChar.ToString();
            if (!Char.IsPunctuation(e.KeyChar))//如果是字符的话
            {
                if ((key != " ")) //除了空格键外不响应
                {
                    
                    e.Handled = true;
                }
                else
                {
                    EditCell.Text="+";     //如果是空格键,该单元格的字符赋值为+
                    Frm_Main.SendKeys.Send("{TAB}"); 
                    //如果是单元格的话,希望再发送tab,光标进入同一行的下一列。                               
                    e.Handled = true;
                      
                }
               
            
            }
            
        } Frm_Main.SendKeys.Send("{TAB}"); 
//如果是单元格的话,希望再发送tab,光标进入同一行的下一列。这个不能正常工作,键入空格键后,光标会乱跳,有时候移入同一行下一列,有时候可能立即移动到 下一行下一列去了,这是为什么?怎么解决?

解决方案 »

  1.   

    按照顺序设置一遍每个控件的TabIndex属性。TabIndex属性决定了控件之间的前后关系。
      

  2.   

    按照顺序设置一遍每个控件的TabIndex属性。
    这个怎么设置,难道要遍历dataGridview1中的所有单元格吗?在程序运行的时候,按实体键盘tab是正常的,准确移到同一行的下一列。
      

  3.   

    发现
    SendKeys.Send("{TAB}"); 
    第一次是正常的,进入下一个单元格,第二次跳过2格,第三次跳过4格,好像是这样。