Home Forums WinForms controls Xceed Grid for WinForms keyboard events

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16062 |

    Hi,

    First, i want to say Thanks for this  great usefull xceed grid control.

    when i used to create cell_MouseEnter event as below it is working fine 

    Dim cell As DataCell

    For Each cell In GridControl1.DataRowTemplate.Cells

    AddHandler cell.MouseEnter, AddressOf Me.ShowTip

    Next

    But when i used to create keyboard event as below it is not working fine 

    Dim cell As DataCell

    For Each cell In GridControl1.DataRowTemplate.Cells

    AddHandler cell.KeyPress, AddressOf Me.cell_keypress

    Next

    On keypress in the xceed grid datarow cell, this cell_keypress event is not even executing. 

    Please advise me on this. 

    Imported from legacy forums. Posted by pravi (had 901 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    Inorder to handle the keyboard events i implemented the following code

    Private Sub CreateTextBoxes(ByVal paramName As String, ByVal index As Integer)

    Dim dataRow As DataRow

    dataRow = GridControl1.DataRows.AddNew()

    Dim txtBox As New WinTextBox()

    Dim txtEditor As New TextEditor(txtBox)

    Dim txtViewer As New TextViewer(txtBox)

    AddHandler txtEditor.ActivatingControl, AddressOf txtEditor_ActivatingControl

    AddHandler txtEditor.DeactivatingControl, AddressOf txtEditor_DeactivatingControl

    dataRow.Cells(“Value”).CellEditorManager = txtEditor

    dataRow.Cells(“Value”).CellViewerManager = txtViewer

    dataRow.Cells(“Parameter”).Value = paramName

    dataRow.EndEdit()

    End Sub

     

     Private Sub txtEditor_ActivatingControl(ByVal sender As Object, ByVal e As CellEditorEventArgs)

    Dim txtBox As WinTextBox = CType(e.Control, WinTextBox)

    AddHandler txtBox.KeyPress, AddressOf txtBox_keypress

    End Sub

     

     Private Sub txtEditor_DeactivatingControl(ByVal sender As Object, ByVal e As CellEditorEventArgs)

    Dim txtBox As WinTextBox = CType(e.Control, WinTextBox)

    RemoveHandler txtBox.KeyPress, AddressOf txtBox_keypress

    End Sub

     

    Private

    Sub txtBox_keypress(ByVal sender As Object, ByVal e As KeyPressEventArgs)

    Dim a As Integer = GridControl1.DataRows.Count

    End Sub

     On mouse click of the cell the event “txtEditor_ActivatingControl” is executing but on keypress in that cell (textbox), txtBox_keypress event is not executing.

    Please advise me on this.

    Imported from legacy forums. Posted by pravi (had 491 views)

    Xceed Support
    Member
    Post count: 5658

    You need to subscribe on the TextBoxArea of the WinTextBox. Something like this:

    AddHandler txtBox.TextBoxArea.KeyPress, AddressOf txtBox_keypress

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the reply.

    Imported from legacy forums. Posted by pravi (had 1014 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.