Key down an datagridview

M

mordock32

chris81 said:
hello
can i make to captur the key down event on cell's datagridview??

thx

I just recently had a need to do this myself. First, you can get the
editing control for that cell by handling the EditingControlShowing
event of the DataGridView. Then you can subscribe to the KeyDown event
of the editing control.
 
C

chris81

Le 01/11/2006, (e-mail address removed) a supposé :
I just recently had a need to do this myself. First, you can get the
editing control for that cell by handling the EditingControlShowing
event of the DataGridView. Then you can subscribe to the KeyDown event
of the editing control.

have you got an example ?

thx
 
C

chris81

Dans son message précédent, chris81 a écrit :
Le 01/11/2006, (e-mail address removed) a supposé :

have you got an example ?

thx

yes i add

Private Sub dataGridView1_EditingControlShowing(ByVal sender As
Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles
dgCompositionFormule.EditingControlShowing

e.CellStyle.BackColor = Color.Aquamarine

End Sub

but how can i captur key ??

thx
 
J

James Daughtry

chris81 said:
Le 01/11/2006, (e-mail address removed) a supposé :

have you got an example ?

thx

In your EditingControlShowing event, do something like this:

dgv.EditingControl.KeyDown += CellKeyDown;

Then define your event handler (CellKeyDown) for the KeyDown event.
 
C

chris81

James Daughtry a formulé la demande :
In your EditingControlShowing event, do something like this:

dgv.EditingControl.KeyDown += CellKeyDown;

Then define your event handler (CellKeyDown) for the KeyDown event.

one complete example please because i don't understand.... :(

thx
 
J

James Daughtry

chris81 said:
James Daughtry a formulé la demande :

one complete example please because i don't understand.... :(

thx

That was a complete example. Presumably you know how to write a KeyDown
even handler, so the only unfamiliar part is the single line I gave
you:

Private Sub dataGridView1_EditingControlShowing(ByVal sender As
Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles
dgCompositionFormule.EditingControlShowing
dgCompositionFormule.EditingControl.KeyDown += CellKeyDown
End Sub

Private Sub CellKeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
' Whatever you want to do when the key is down here
End Sub
 
C

chris81

James Daughtry avait écrit le 03/11/2006 :
That was a complete example. Presumably you know how to write a KeyDown
even handler, so the only unfamiliar part is the single line I gave
you:

Private Sub dataGridView1_EditingControlShowing(ByVal sender As
Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles
dgCompositionFormule.EditingControlShowing
dgCompositionFormule.EditingControl.KeyDown += CellKeyDown
End Sub

Private Sub CellKeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
' Whatever you want to do when the key is down here
End Sub

thanks
 

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