Datagridviewcell keypres...

S

sonsuzoyku

Hi,

There is no keypress event for datagridviewcell items... That is a
nightmare. I would like to save data to database on the grid when users
press to enter after changing value of a cell on the grid. But only
cellleave event is running on current cell. I tried to create a custom
cell and column and there is no success :( ... Any idea?

Thanks
 
K

Kevin Spencer

Handle the CellendEdit event. This event is called after the CellValidating
event, which is called after the CellLeave event:

1) CellLeave (old cell)
2) Cell Validating/ed (old cell)
3) CellEndEdit (old cell)

--
HTH,

Kevin Spencer
Microsoft MVP
Short Order Coder
http://unclechutney.blogspot.com

The devil is in the yada yada yada
 
S

sonsuzoyku

Kevin, thanks for the replay,

But i am paranoid :). I would like to update the entire row in one db
call therefore i have to handle "enter key" press. Can i determine
which key is pressed in cellendedit method?

Best regards...



Kevin Spencer yazdi:
 
K

Kevin Spencer

I'm afraid not. You *could* write a custom DataGridViewColumn, and related
Controls, but that is an awful lot of work. I've done it before!

--
HTH,

Kevin Spencer
Microsoft MVP
Short Order Coder
http://unclechutney.blogspot.com

The devil is in the yada yada yada
 
S

sonsuzoyku

Hi Kevin and thank you,

What the trouble I dived into :). I wrote a custom datagridview edit
control, column and cell and I overrided KeyDown event of the edit
control. It works fine for all keys except return key :)))). When I
press to enter, the KeyDown event does not being fired. Is the enter
key a witch? How can it escape from the KeyDown event? Is that a
nightmare :) I really curious about its cause...

Thanks and Regards...
 
K

Kevin Spencer

It is possible that the KeyDown event is being intercepted at a higher
level, such as at the DataGridView level itself, which does have a KeyDown
event handler. I'm not sure. You could work your way up, and check out where
the KeyDown event is handled first, then determine which cell (if any)
currently has the focus.

--
HTH,

Kevin Spencer
Microsoft MVP
Short Order Coder
http://unclechutney.blogspot.com

The devil is in the yada yada yada
 
B

Brendon Bezuidenhout

Heya sonsuzoyku,

Have you tried the RowValidating event yet? I use it to trap if a row
isCurrentRowDirty and then save as I do... You do need to set up a boolean
value for when you are opening your form or the event gets called each time
a new row is painted and populated into the grid

Code:
Private Sub dgvCurrentYear_RowValidating(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles
dgvCurrentYear.RowValidating
If Not m_initialising Then
If DirectCast(sender, DataGridView).IsCurrentRowDirty Then
dirtyRowSave(DirectCast(sender,
DataGridView).CurrentRow.Index)
End If
End If
End Sub

HTH
Brendon
 
S

sonsuzoyku

Thanks for the response Brendon that solves my problem... But the
KeyDown event is still in suspense :). When i will got enough time, i
will perform some work arount about it. Thanks again...



Brendon said:
Heya sonsuzoyku,

Have you tried the RowValidating event yet? I use it to trap if a row
isCurrentRowDirty and then save as I do... You do need to set up a boolean
value for when you are opening your form or the event gets called each time
a new row is painted and populated into the grid

Code:
Private Sub dgvCurrentYear_RowValidating(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles
dgvCurrentYear.RowValidating
If Not m_initialising Then
If DirectCast(sender, DataGridView).IsCurrentRowDirty Then
dirtyRowSave(DirectCast(sender,
DataGridView).CurrentRow.Index)
End If
End If
End Sub

HTH
Brendon

sonsuzoyku said:
Hi Kevin and thank you,

What the trouble I dived into :). I wrote a custom datagridview edit
control, column and cell and I overrided KeyDown event of the edit
control. It works fine for all keys except return key :)))). When I
press to enter, the KeyDown event does not being fired. Is the enter
key a witch? How can it escape from the KeyDown event? Is that a
nightmare :) I really curious about its cause...

Thanks and Regards...
 

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