1、想在一个单元格A中输入数字的时候,另一个单元格B的内容实时改变。原来用CellValueChanged,效果不太好,因为只能是在A中输入完了之后,再点一下别的地方(等A焦点完全消失),B才能改变;
2、有人说用KeyDown事件,我试了,可发现这个KeyDown是对于dataGridView响应的,也就是说当前焦点在dataGridView上面时,我按下键盘就会触发。
3、纠结中。
4、多指教!多谢!

解决方案 »

  1.   

    判断Dataset.haschanges
    public new bool ProcessRightKey(Keys keyData)
      {
      Keys key = (keyData & Keys.KeyCode);
      if (key == Keys.Enter)
      {
      if ((base.CurrentCell.ColumnIndex == (base.ColumnCount - 1)) && (base.RowCount == 1))
      {
      base.CurrentCell = base.Rows[base.RowCount - 1].Cells[0];
      return true;
      }
      if ((base.CurrentCell.ColumnIndex == (base.ColumnCount - 1)) && (base.CurrentCell.RowIndex < (base.RowCount - 1)))
      {
      base.CurrentCell = base.Rows[base.CurrentCell.RowIndex + 1].Cells[0];
      return true;
      }  return base.ProcessRightKey(keyData);
      }
      return base.ProcessRightKey(keyData);
      }
      

  2.   

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
      if (e.RowIndex > 0)
      {
      dataGridView1.CommitEdit(System.Windows.Forms.DataGridViewDataErrorContexts.Commit);
      }
    }
      

  3.   

    谢谢人生如梦,我最后用的是:
    在CurrentCellDirtyStateChanged事件中,将CommitEdit()写了进去。
    还请问下你写的ProcessRightKey函数作用是什么呢?我直接定义了cellValueChanged()事件了。
    再次感谢你的思路!