Home Forums WinForms controls Xceed Grid for WinForms keyboard events Reply To: keyboard events

Xceed Support
Member
Post count: 5658

These events will only be triggered as long as the DataCell is not in Edit mode. So, your KeyPress event should have been executed once. However, after the DataCell goes into Edit mode, so you need to monitor the KeyPress of the CellEditorManager.

To do so, you subscribe to the ActivatingControl event on the CellEditorManager of the wanted DataCells. In the ActivatingControl event, you cast the e.Control parameter as the Cell Editor (a WinTextBox for example). And you Manage the KeyPress event on it.

Code sample:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) 
    ‘…
    
    For Each cell As DataCell In gridControl1.DataRowTemplate.Cells
        AddHandler cell.CellEditorManager.ActivatingControl, AddressOf CellEditorManager_ActivatingControl
        AddHandler cell.CellEditorManager.DeactivatingControl, AddressOf CellEditorManager_DeactivatingControl
    Next
End Sub

Private Sub CellEditorManager_ActivatingControl(ByVal sender As Object, ByVal e As CellEditorEventArgs)
    AddHandler DirectCast(e.Control, WinTextBox).TextBoxArea.KeyPress, AddressOf TextBoxArea_KeyPress
End Sub

Private Sub CellEditorManager_DeactivatingControl(ByVal sender As Object, ByVal e As CellEditorEventArgs)
    RemoveHandler DirectCast(e.Control, WinTextBox).TextBoxArea.KeyPress, AddressOf TextBoxArea_KeyPress
End Sub

Private Sub TextBoxArea_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
    ‘Handle the KeyPress
End Sub

Imported from legacy forums. Posted by CharlesB (had 598 views)