Windows Forms Datagrid and Form.KeyPreview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl Tribble

    #1

    Windows Forms Datagrid and Form.KeyPreview

    I am using KeyPreview on the form to trap Function-keys. My form includes a
    datagrid. I am using the Form.KeyDown event to trap the keys and all works
    fine unless the datagrid is showing one or more rows and the focus is in a
    column on one of the datagrid's rows. Then, pressing a function key does
    not seem to execute the Form.KeyDown event.

    How can I trap and detect which function key a user pressed at the form
    level from inside of a filled datagrid?

    Thanks,
    -Carl


  • Ken Tucker [MVP]

    #2
    Re: Windows Forms Datagrid and Form.KeyPreview

    Hi,



    Ken
    ------------------
    "Carl Tribble" <carl@tribbleso ftware.com> wrote in message
    news:%23u5NwKjg FHA.1248@TK2MSF TNGP12.phx.gbl. ..
    I am using KeyPreview on the form to trap Function-keys. My form includes a
    datagrid. I am using the Form.KeyDown event to trap the keys and all works
    fine unless the datagrid is showing one or more rows and the focus is in a
    column on one of the datagrid's rows. Then, pressing a function key does
    not seem to execute the Form.KeyDown event.

    How can I trap and detect which function key a user pressed at the form
    level from inside of a filled datagrid?

    Thanks,
    -Carl



    Comment

    • Carl Tribble

      #3
      Re: Windows Forms Datagrid and Form.KeyPreview

      Thanks, Ken. I downloaded the sample code and experimented with it for
      awhile. It works of course but it also produces some side effects that, in
      my case at least, are undesirable. For one you can no longer select an
      entire row by clicking on the row header. You have to click it twice.
      Also, and more importantly, it seems that you can not delete the contents of
      a cell.

      Perhaps these matters can be fixed by altering the code slightly. I tried a
      few things with no success. Is there another solution to this problem? Or
      do you know a way to deal with those side-effects (at least the not being
      able to delete problem)?

      Thanks,
      -Carl

      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
      news:%23XhsM5tg FHA.2180@TK2MSF TNGP15.phx.gbl. ..[color=blue]
      > Hi,
      >
      > http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp#q836q
      >
      > Ken
      > ------------------
      > "Carl Tribble" <carl@tribbleso ftware.com> wrote in message
      > news:%23u5NwKjg FHA.1248@TK2MSF TNGP12.phx.gbl. ..
      > I am using KeyPreview on the form to trap Function-keys. My form includes
      > a
      > datagrid. I am using the Form.KeyDown event to trap the keys and all
      > works
      > fine unless the datagrid is showing one or more rows and the focus is in a
      > column on one of the datagrid's rows. Then, pressing a function key does
      > not seem to execute the Form.KeyDown event.
      >
      > How can I trap and detect which function key a user pressed at the form
      > level from inside of a filled datagrid?
      >
      > Thanks,
      > -Carl
      >
      >
      >[/color]


      Comment

      Working...