Enter Key Problem -Datagridview Editing Mode - Paricular Cell Focus

Hi,

I have a class for MyDataGridView - To control the Enter Key , the below is working fine. But I canot focus to particular row for repeated values.

Actually if the user enters the repeated value, then the control has to move to that particular cell.
-------------------------------------------------

Public Class MyDataGrid
Inherits DataGridView

Protected Overloads Overrides Function ProcessDialogKey(ByVal keyData As Keys) As Boolean
If keyData = Keys.Enter Then
Dim col As Integer = Me.CurrentCell.ColumnIndex
Dim row As Integer = Me.CurrentCell.RowIndex
If Not (row = Me.NewRowIndex) Then
If col = (Me.Columns.Count - 1) Then
col = -1
row += 1
End If
Me.CurrentCell = Me(col + 1, row)
End If
Return True
End If
Return MyBase.ProcessDialogKey(keyData)
End Function

Protected Overloads Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
If e.KeyData = Keys.Enter Then
Dim col As Integer = Me.CurrentCell.ColumnIndex
Dim row As Integer = Me.CurrentCell.RowIndex
If Not (row = Me.NewRowIndex) Then
If col = (Me.Columns.Count - 1) Then
col = -1
row += 1
End If
Me.CurrentCell = Me(col + 1, row)
End If
e.Handled = True
End If
MyBase.OnKeyDown(e)
End Sub

End Class
----------------------------------------------
with my form

Private Sub MyDataGrid1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MyDataGrid1.CellEndEdit

If MyDataGrid1.CurrentCell.ColumnIndex = 0 Then
Dim RwNum As Integer = 0
Dim ep_id As String = Space(10)
ep_id = MyDataGrid1.CurrentCell.Value
RwNum = dbndf_52.Find("emp_id", ep_id)
If RwNum > 0 Then
MyDataGrid1.CurrentCell = MyDataGrid1(0, RwNum)
End If

End If

End sub

It's moving to that new row but again, retun to the previous row and moving to next column. This is my problem.

Any Better Ideas For Me?

Thanks Again

Comments

  • Hi,

    After a big fight, I solved it from DataGridView_Editing Control Showing-Key_down.

    Thanks Again.

  • seancampbellseancampbell Pennsylvania, USA
    I fight with my code a lot too, thats why I take martial arts classes, I have been beat up by code too much
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!

Categories