This is a migrated thread and some comments may be shown as answers.

Invalid character & Back Space behavior

3 Answers 57 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
DP
Top achievements
Rank 1
DP asked on 21 Jul 2008, 01:06 AM
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

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 23 Jul 2008, 07:00 PM
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.
0
DP
Top achievements
Rank 1
answered on 11 Sep 2008, 08:49 AM
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
0
Dimitar Kapitanov
Telerik team
answered on 11 Sep 2008, 04:04 PM
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.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
DP
Top achievements
Rank 1
Answers by
Georgi
Telerik team
DP
Top achievements
Rank 1
Dimitar Kapitanov
Telerik team
Share this question
or