user2452250
user2452250

Reputation: 797

get value of the cell that is currently beeing edited

I need to get the text that the user is currently typing into a datagridview cell.

DataGridView2.CurrentCell.Value returns the old value until the user finishes editing it, but I need to verify it while he is typing.

How can i do that?

Thanks

Upvotes: 0

Views: 513

Answers (1)

WozzeC
WozzeC

Reputation: 2660

You can do this by creating an eventhandler for EditingControlShowing. Then all you have to do is setup an eventhandler for textchanged on the DatagridViewCell Textbox.

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

Upvotes: 1

Related Questions