VB.NET下完美解决datagridview KeyPress 无响应问题

来源:互联网 发布:windows git服务器 编辑:程序博客网 时间:2024/05/07 02:47

为了联想输入需要,要实时取得当前输入的值,用了网上很多方法,都是很麻烦的。本人试了各种事件后,发现以下方式就可以了,发代码出来给大家学习一下。

 Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged

        '接管datagridview 的正在编辑事件,这个是很关键的代码
        DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)   '实时提交改为当前输入

                      ‘这样就可以接管当前输入的DataGridView1.CurrentCell.Value这个值,完成keypress事件           ‘DataGridView1.CurrentCell.Value         '用当前改变的输入做为联想

          ‘例如 IF DataGridView1.CurrentCell.Value=XXXX  THEH XXX

  End Sub
1 0