Overriding key-presses in WinForms DataGrid

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

I have a datagrid and I would like to prevent the users
from pressing the left or right key to change cells. I
only want the up and down buttons to still work - and I
want them to be limited to editing a single column in the
datagrid.

One thing I originally did was had it so if you pressed
left or right, it would refocus on the column I want - but
that will cause the CellChange event to trigger twice,
which just won't work...

Any Ideas?

Thanks
-Adam
 
Hey Adam,

You could try inheriting from the DataGrid and overriding the WndProc
procedure. When you receive a message for arrow left and right (m.Msg ==
VK_LEFT ...), don't pass these on to the base.WndProc( ). This way you can
filter what types of messages (i.e. events) are handed to the event loop of
the control. You can also try overriding the PreProcessMessage. This link
may help explain it a little better with a similar example.

http://www.codeproject.com/cs/miscctrl/extendedlistviews.asp?print=true

- Chris
 
Back
Top