Overriding key-presses in WinForms DataGrid

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
 
C

Chris Willis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top