Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Automatically leave a DataGridView Cell

franciscanmonkfranciscanmonk Posts: 4Member
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

Comments

  • aspongeasponge Posts: 42Member
    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.
  • franciscanmonkfranciscanmonk Posts: 4Member
    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.