Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i have a codes for selecting right cell in datagridview when datagridview cell changed or press enter key

but codes running always when i press enter key

how can i do this only i'm in datagridview ?

What I have tried:

Private KeyHandled As Boolean
   Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
       If FAT_TABLO.RowCount = 0 Then Exit Function

       Dim icolumn As Integer = FAT_TABLO.CurrentCell.ColumnIndex
       Dim irow As Integer = FAT_TABLO.CurrentCell.RowIndex

       If keyData = Keys.Enter Then
           If icolumn = FAT_TABLO.Columns.Count - 1 Then
               FAT_TABLO.Rows.Add()
               FAT_TABLO.CurrentCell = FAT_TABLO(0, irow + 1)
           Else
               FAT_TABLO.CurrentCell = FAT_TABLO(icolumn + 1, irow)
           End If
           Return True
       Else
           Return MyBase.ProcessCmdKey(msg, keyData)
       End If
   End Function
Posted
Updated 23-Jul-20 20:38pm

1 solution

You should work with the Events from your DataGridView which matches to your Requirement.
Actually it seams to me that you are working with the method of your Form.
 
Share this answer
 
Comments
Member 14588284 24-Jul-20 7:14am    
when i select a textbox then press enter key runnig this code
Ralf Meier 24-Jul-20 8:19am    
Have you tried to attach the method DIRECTLY to an Event of your DGV ?
Of course ... using this method of your Form works ... but as you described : not as you want ... :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900