Home Forums WinForms controls Xceed Grid for WinForms Numeric Combobox Editor with AllowFreeText=True

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

    How do I create a Cell that supports NUMERIC only like a Numeric editor but has a dropdown control with a list of common values? It must support AllowFreeText = True.

    Example:
    Dim t_Column1 As New Xceed.Grid.Column(“Fld 1”)
    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
    t_Column1.CellEditorManager = t_CboNumber
    Grid1.Columns.Add(t_Column1)

    I can put a handler on the cell like so;

    AddHandler Grid1.DataRowTemplate.Cells(1).KeyPress, AddressOf CellKeypress
    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

    — This only fires while the user presses a TEXT key. The minute they press a numeric they open up the combobox editor, at which point they can then type in letters.
    I can’t find where to trap the editor keypress event.

    I have tried the following;
    ‘// TRAPS THE KEYPRESS EVENT… BUT NO WAY TO HANDLE HANDLE IT.
    AddHandler t_CboNumber.QueryInputKey, AddressOf cboNumber_QueryInputKey

    ‘// CAN’T FIGURE OUT HOW TO GET THE BELOW EVENTS TO FIRE.
    AddHandler t_CboNumber.TemplateControl.KeyPress, AddressOf CboTempalte_Keypress
    AddHandler t_CboNumber.QueryInputChar, AddressOf cboNumber_QueryInputChar

    Imported from legacy forums. Posted by Rock (had 2155 views)

    User (Old forums)
    Member
    Post count: 23064

    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)

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