* (e-mail address removed)-spam.invalid (robert_rowe) scripsit:
Does anyone know how to detect keypresses in a Datagrid cell? The
Keypress event ofthe datagrid doesn't fire if you are in a cell.
Neither does KeyUp & KeyDown. I've tried hooking in to the
DataGridCell events but it doesn't have the keypress event.
You will have to take the 'KeyPress' event of the cell. In order to do
that, you will have to derive a class from 'DataGridColumnStyle' and
assign your own 'GridColumnStyle' of your 'TableStyle'. Then you add a
handler to the 'KeyPress' event of the class created in the last step.
Source code (taken from a post by Peter Fleischer):
\\\
....
Me.DataGrid1.TableStyles.Clear()
Dim dgts As New DataGridTableStyle
dgts.MappingName = "Tab1"
Me.DataGrid1.TableStyles.Add(dgts)
Dim myTextBoxColumn As DataGridTextBoxColumn = _
DataGrid1.TableStyles("Tab1").GridColumnStyles("Feld2")
Dim dgtb As DataGridTextBox = _
CType(myTextBoxColumn.TextBox, DataGridTextBox)
AddHandler dgtb.KeyPress, AddressOf meineTastenPresse
....
Private Sub meineTastenPresse(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs)
Debug.WriteLine("Gedrückt: " & Asc(e.KeyChar).ToString)
End Sub
///