[Closed] DataGridView keyDown
I’m using “system.windows.forms.dataGridView” and I want to have an event fired when a key is pressed. The enter key is more specific, how ever on keyDown, keyUp or keyPress don’t appear to be doing anything at all.
Any suggestions?
Well right now the only way I can get it to work is when I leave a cell. This has to be done with arrow keys or with the mouse. What I would like is for enter to force an event on the cel just as it would with and editText box or spinner. Doesn’t feel natural that enter doesn’t do this already.
Don’t know if this will help, but some controls have an ‘acceptsReturn’ property that needs to be set to True before the enter key will be recognized.
Thanks but it isn’t there. I gather from what I have found in google I’m not the only one. Looks like it is a pain to do.
From what I understand I need to use the keydown event that is on the EditingControlShowing event. I don’t have a clue how to go about that.
Like I need to call and event that calls an event. Any one?
Here is an explanation from the developer. I don’t have a clue what it means.
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/dc6d4d47-dbb1-42d5-954e-16c5645c89bb
don’t read any BSHT
everything is easy:
use EditingControlShowing event to get cell control
fn keyDown s e =
(
format "key down: %
" e
)
fn keyUp s e =
(
format "key up: %
" e
)
on gridView EditingControlShowing s e do
(
cc = e.Control
cc.AcceptsReturn = on -- if you want to catch "Enter"
dotNet.addEventHandler cc "KeyDown" keyDown
dotNet.addEventHandler cc "KeyUp" keyUP
)
I’ll try not to, how ever you code isn’t working either. Maybe this has something to do with it being in a scripted geometry plugin. I already tried what you have and played with making the function global as I remember some one talking about similar issues with event handlers.
I will try and whip up some sample code in a bit.
Here it is as a modifier as that was easier to set up
plugin modifier AAA
name:"AAA"
classId:#(0x105358d1, 0x3490f0cb)
(
fn initDGV dgv columnAr:#()=
(
dgv.columnCount=columnAr.count
for i = 1 to columnAr.count do
(
dgv.columns.item[i-1].name=columnAr[i]
)
)
fn keyDown senderArg arg=
(
format "KeyDown: %
" arg
)
rollout testR "Test"
(
dotNetControl dgv "system.windows.forms.dataGridView" height:100
on dgv EditingControlShowing senderArg arg do
(
arg.control
arg.control.acceptsReturn=on
dotNet.addEventHandler arg.control "KeyDown" keyDown
)
on testR open do
(
initDGV dgv columnAr:#("Test1")
)
)
)
it has to work…
try(destroydialog gvRol) catch()
rollout gvRol "by denisT"
(
dotNetControl gv "System.Windows.Forms.DataGridView" pos:[1,0] width:250 height:100
on gvRol open do
(
labels = #("", "")
gv.ColumnCount = labels.count
for i=1 to labels.count do gv.Columns.item[i-1].name = labels[i]
gv.rows.add #((dotNetObject "System.String" "some"), (dotNetObject "System.String" "thing"))
)
on gv keyup s e do (format "grid key down: %
" e)
on gv keydown s e do (format "grid key up: %
" e)
fn keyDown s e = (format "text key down: %
" e)
fn keyUp s e = (format "text key up: %
" e)
on gv EditingControlShowing s e do
(
e.Control.AcceptsReturn = on
dotNet.addEventHandler e.Control "KeyDown" keyDown
dotNet.addEventHandler e.Control "KeyUp" keyUp
)
)
createDialog gvRol width:250 height:100