Home › Forums › WinForms controls › Xceed Grid for WinForms › Numeric Combobox Editor with AllowFreeText=True › Reply To: Numeric Combobox Editor with AllowFreeText=True
For the KeyPress event, you need to subscribe to it when the editor actually becomes active, and for the QueryInputKey and QueryInputChar, you need to subscribe to the ones that are on the CellEditorManager.
e.g. :
Dim t_CboNumber As New Xceed.Grid.Editors.ComboBoxEditor
t_CboNumber.TemplateControl.Items.Add(1)
t_CboNumber.TemplateControl.Items.Add(5)
t_CboNumber.TemplateControl.Items.Add(10)
t_CboNumber.TemplateControl.Items.Add(15)
t_CboNumber.TemplateControl.Items.Add(20)
t_CboNumber.TemplateControl.AllowFreeText = True
GridControl1.Columns( 3 ).CellEditorManager = t_CboNumber
AddHandler GridControl1.DataRowTemplate.Cells( 3 ).KeyPress, AddressOf CellKeypress
AddHandler GridControl1.Columns( 3 ).CellEditorManager.QueryInputKey, AddressOf Col3_CellEditorManager_QueryInputKey
AddHandler GridControl1.Columns( 3 ).CellEditorManager.ActivatingControl, AddressOf Col3_CellEditorManager_ActivatingControl
AddHandler GridControl1.Columns( 3 ).CellEditorManager.DeactivatingControl, AddressOf Col3_CellEditorManager_DeactivatingControl
//HANDLERS
Private Sub CellKeypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
If IsNumeric( e.KeyChar ) then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub Col3_CellEditorManager_QueryInputKey( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.QueryEditorInputKeyEventArgs )
Dim editor as WinComboBox = CType( e.Control, WinComboBox)
System.Diagnostics.Debug.WriteLine( “in QueryInputKey” )
End Sub
Private Sub Col3_CellEditorManager_ActivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )
Dim editor as WinComboBox = CType( e.Control, WinComboBox)
AddHandler editor.TextBoxArea.KeyPress, AddressOf editor_KeyPress
End Sub
Private Sub Col3_CellEditorManager_DeactivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )
Dim editor as WinComboBox = CType( e.Control, WinComboBox)
‘this needs to be done, if not, subscriptions will pill up every time the editor is activated
RemoveHandler editor.TextBoxArea.KeyPress, AddressOf editor_KeyPress
End Sub
Private Sub editor_KeyPress( ByVal sender As Object, ByVal e As KeyPressEventArgs )
System.Diagnostics.Debug.WriteLine( “in KeyPress of editor” )
End Sub
Imported from legacy forums. Posted by André (had 3131 views)