Automatically leave a DataGridView Cell

I am trying to automatically LEAVE a DataGridView Cell after entering 2 characters, (without pressing Enter or Tab keys).

I have exhausted all options and am hoping there is a guru out there who can help. I have experimented with Events such as CellValueChanged, and EditingControlShowing, but I can


  • Use the EditControlShowing event which is fired whenever the user begins editing a grid cell. The event handler passes an EditControlEventArgs object which contains a Control property. This is the control used to edit the cell data. What you can do is register the TextChanged event on this control. When the text changes, and two characters have been entered, then set the DataGridView.CurrentCell property to whatever cell you want to move to.
  • Thanks asponge for your assistance.
    I had a problem with the "EditingControlShowing" event firing multiple times. Got around it with the following code.

    Private Sub dgView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgView1.EditingControlShowing
    If Formloading = True Then Exit Sub
    If Not e.Control Is Nothing Then
    RemoveHandler e.Control.TextChanged, New EventHandler(AddressOf CellTextChanged)
    AddHandler e.Control.TextChanged, New EventHandler(AddressOf CellTextChanged)
    End If

    End Sub

    Note: Formloading is a local variable. Removing the handler was the trick; otherwise the handler is assigned multiple times.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!