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

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

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

jim

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
 
S

SStory

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
 
S

SStory

Thanks Jim,

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

Thanks again.

Shane
 

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