catching keystrokes from a Datagrid cell---that should be form wide--like F6, F7, etc.

  • Thread starter Thread starter SStory
  • Start date Start date
S

SStory

I want to use F6,F7,etc for an entire form.

Have key preview to true and it works everywhere but on the grid.
On the grid sometimes it works and sometimes not.

Appears that if I am in a cell and press one of them it won't work.

Any ideas?

Shane
 
Hi,

Try to override the grid's ProcessDialogKey and ProcessKeyPreview methods to
prevent them from "eating" these keys.
 
Hi Shane, each datagrid cell is actually it's own control. To capture
keystrokes within the datagrid cell you must dynamically add a handler to
each cell at runtime. something along the lines of

dim myControl as Control
for each myControl in myDataGrid.Controls
addhandler mycontrol.KeyDown, addressof myHandler
next

i wrote this code off the top of my head so it's not tested, but you can
find more than enough examples of this if you do a search on google in the

microsoft.public.dotnet.framework.windowsforms.controls

group.

http://tinyurl.com/xd7i

hope this helps a little,

Jim
 
Thanks, although I didn't want to inherit the control just wanted to use it.

Dmitriy Lapshin said:
Hi,

Try to override the grid's ProcessDialogKey and ProcessKeyPreview methods to
prevent them from "eating" these keys.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

SStory said:
I want to use F6,F7,etc for an entire form.

Have key preview to true and it works everywhere but on the grid.
On the grid sometimes it works and sometimes not.

Appears that if I am in a cell and press one of them it won't work.

Any ideas?

Shane
 
Thanks Jim,

took a little fooling around with but worked great! I had tried everything.

Thanks again.

Shane
 
Back
Top