0
我需要获取用户当前正在键入到datagridview单元格中的文本。获取当前正在编辑的单元格的值
DataGridView2.CurrentCell.Value
返回旧值直到用户完成编辑它,但我需要在键入时验证它。
我该怎么做?
感谢
我需要获取用户当前正在键入到datagridview单元格中的文本。获取当前正在编辑的单元格的值
DataGridView2.CurrentCell.Value
返回旧值直到用户完成编辑它,但我需要在键入时验证它。
我该怎么做?
感谢
您可以通过创建EditingControlShowing的事件处理程序做到这一点。然后你所要做的就是在DatagridViewCell文本框中为textchanged设置一个事件处理程序。
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If DataGridView1.CurrentCell.ColumnIndex = 0 Then
Dim tb As TextBox = CType(e.Control, TextBox)
AddHandler tb.TextChanged, AddressOf tb_TextChanged
End If
End Sub
Private Sub tb_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim tb As TextBox = CType(sender, TextBox)
Dim s As String = tb.Text
End Sub
非常感谢! – user2452250