我需要将用户当前正在键入的文本放入datagridview单元格中。
DataGridView2.CurrentCell.Value
返回旧值,直到用户完成编辑,但我需要在输入时验证它。
我该怎么做?
由于
答案 0 :(得分:1)
您可以通过为EditingControlShowing创建事件处理程序来完成此操作。然后,您所要做的就是在DatagridView单元格文本框上为textchanged设置一个eventhandler。
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