• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Help with Controling ENTER KEY inside a DataGrid

I have a datagrid that shows a list of customers.  Currently I have some code in the double click event of the data grid that fires when they double click on the row header.  I first would like to be able to use my arrow keys to move up and down on the grid to the row the user wants.  This already works except it only highlights the cell they are in.. I would like for it to keep the whole row highlghted at all times.  This grid is never used for updating.. its read only.  Ones the user is on the row they want, i would like them to be able to hit the ENTER KEY that would basicly fire the same code as the DOUBLE CLICK EVENT does?

Any suggestions on this?

Thanks!!!!
0
accmats
Asked:
accmats
  • 2
1 Solution
 
RonaldBiemansCommented:
use the currenccellchange event

like

 Private Sub dg_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
        DataGrid1.Select(DataGrid1.CurrentRowIndex)

    End Sub
0
 
accmatsAuthor Commented:
ok... that worked to highlight the rows as I use the down arrow to get to the need row.  Now how can I capture the ENTER KEY and make it do basicly the same code I currently have the DOUBLE CLICK event doing?
0
 
RonaldBiemansCommented:
Hi accmats, well that is a bit more difficult, you have to create your own datagrid (and use that datagrid) and override the ProcessCmdKey, like

Public Class MyDataGrid
          Inherits DataGrid

          Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As Boolean
               If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
                     yourdoubleclickevent(nothing,nothing)
                    Return True
               End If
               Return MyBase.ProcessCmdKey(msg, keyData)
          End Function 'ProcessCmdKey

     End Class
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now