RE: Capture ENTER key in vb.net datagrid

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Foef (Foef_at_discussions.microsoft.com)
Date: 01/25/05


Date: Tue, 25 Jan 2005 09:13:03 -0800

Steve,

To capture keypress event in a datagrid you should use the ProcessCmdKey
function.

for example:
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
             SendKeys.Send("{Tab}")
             Return True
        End If

OR
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104
        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
           Select Case (keyData)
              Case (Keys.Control Or Keys.M)
              Case (Keys.Alt Or Keys.Z)
              Case Keys.Delete
           End Select
        End If
          
        Return MyBase.ProcessCmdKey(msg, keyData)
   End Function 'ProcessCmdKey

End Class 'MyDataGrid

Greetinx,
Foef

"Melson" wrote:

> hi
>
> can anyone help me how can i capture ENTER keystroke when the cell in
> datagrid is in editing mode.
>
> I'm now creating a data entry form with primary key in header and details in
> datagrid. So when user key in the details in datagrid, I would like user to
> choose product code by pressing ENTER key in the datagrid and a Product Code
> dialog will appear for him to choose.
>
> Pls help. Thanks very much.
>
> Regards
> Steve
>
>
>



Relevant Pages

  • Re: Capture ENTER key in vb.net datagrid
    ... Public Class Form1 ... > To capture keypress event in a datagrid you should use the ProcessCmdKey ... > Public Class MyDataGrid ... So when user key in the details in datagrid, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Changing the Cursor on a DataGrid Cell
    ... One way you can do this is to derive the datagrid and handle the ... WM_SETCURSOR message yourself in a WndProc override. ... Public Class MyDataGrid ... however I'm not sure what object to change the cursor on. ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Key events in datagrid control
    ... > Public Class MyDataGrid ... > Public Sub New ... > keyData As Keys) As Boolean ... >> particular while inside a datagrid? ...
    (microsoft.public.dotnet.languages.vb)
  • GridVScrolled
    ... I need to programmatically scrolled to a row on a datagrid ... Public Class MyDataGrid ... Inherits DataGrid ... Sub ScrollToRow ...
    (microsoft.public.dotnet.framework.windowsforms.databinding)
  • Re: Backslash in datagrid not working
    ... I managed to fix it by overriding the ProcessCmdKey method and adding ... > I have a databound datagrid. ... > It works fine for any charachters, ... When I enter a backslash it seems as if the editbox looses ...
    (microsoft.public.dotnet.framework.windowsforms)