Posted by: Sourav | June 1, 2015

Detect backspace on textbox,VB.Net


So when an user press backspace and keep deleting text I want the datagridview show the data accordingly and it is working fine,but when there is nothing to delete anymore which means the textbox is black I want no record (as well as columns) to show up on gridview,Here is how I did it

Private Sub TextBox7_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox7.KeyPress

If (e.KeyChar) = ControlChars.Back Then

If TextBox7.Text.Length = 1 Then
‘MsgBox(“back”)
DataGridView3.DataSource = Nothing
DataGridView3.Rows.Clear()
DataGridView3.Columns.Clear()

End If
End If

End Sub

Interestingly text.length =0 needed another backspace to empty the datagridview,but I want almost instant ajax like response ,line when ever user presses backspace to delete the last character on the textbox,the datagridview should be empty,that’s why I used        If TextBox7.Text.Length = 1 Then

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: