Invalid character & Back Space behavior

4 posts, 0 answers
  1. DP
    DP avatar
    14 posts
    Member since:
    Jul 2008

    Posted 20 Jul 2008 Link to this post

    I have read earlier post on invalid character (where there is no match in list items)and code from a user to handle the invalid character.

    I suggest "AllowFreeText" boolean property for the combo box. If it is set to "False", there should be a beep and not accept the character which results in no match. Also Backspace should remove a user typed characer and append the matching list item.

    I use the following VB (AutoCompletionMode - "Append") code to handle Invalid character and backspace

    Private Sub cboDepartment_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboDepartment.KeyUp

    Dim Lg As Integer
    Dim ComboItem As RadComboBoxItem

    Lg = sender.text.length

    If
    Lg = 0 Then
        Exit Sub
    End If

    If (sender.finditem(sender.text)) Is Nothing Or e.KeyCode = 8 Then
        If Lg = 1 Then
            
    sender.text = ""
            
    Exit Sub
        
    Else
            
    sender.text = sender.text.substring(0, Lg - 1)
        End If

        If e.KeyCode <> 8 Then
            
    Beep()
        End If

        ComboItem = sender.finditem(sender.text)
        sender.text = ComboItem.Text
        sender.SelectionStart = Lg - 1
        sender.SelectionLength = sender.Text.Length - (Lg - 1)

    End If

    End Sub

    Better code suggestions will be highly appreciated.

    Regards ... DP

  2. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 23 Jul 2008 Link to this post

    Hello DP,

    For such cases we would suggest using RadComboBoxElement.TextChanging event as a workaround. The current instance of RadComboBoxElement could be obtained through RadCombobox.ComboBoxElement property. Again in the event handler FindItem method could be used and in case of no match to set TextChangingEventArgs.Cancel property to true. Of course, your approach could also do the work if it is closer to the desired behavior and there are no or not significant side effects.

    As to your suggestion about new property of RadComboBox, I can tell you that we intend to extend the whole autocomplete behavior to handle much more cases including this one.

    Greetings,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. DP
    DP avatar
    14 posts
    Member since:
    Jul 2008

    Posted 11 Sep 2008 Link to this post

    I am adding the radcombobox at design time and the RadComboBox does not have TextChanging event. How does one get to the element of this combobox and add event handler for textchanging?

    Thanks ... DP
  5. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 11 Sep 2008 Link to this post

    Hi DP,
     
    You can access the text element and its TextChanging event by the following API:

    this.radComboBox1.ComboBoxElement.TextBoxElement.TextChanging 

    where this.radComboBox1 is the RadComboBox instance.

    Best wishes,
    Dimitar Kapitanov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top