AutoCompleteBox: Add item with TAB key

2 posts, 1 answers
  1. John
    John avatar
    14 posts
    Member since:
    Apr 2013

    Posted 11 Apr 2013 Link to this post

    Hey Telerik!

    We are looking for a way to have the following functionality.  

    Pressing tab while typing in the AutoCompleteTextbox will create an item.  If the tab key is pressed after an item has been created it will move the curor to the next item in the list.  If the cursor is on the last item then normal tab functionality is used and the next tabbable control has focus.

    I have attached a picture illustrating all of this.

  2. Answer
    Svett avatar
    728 posts

    Posted 16 Apr 2013 Link to this post

    Hello John,

    You can achieve the desired behavior by creating a custom input handler where you can alter the default behavior. You should use the following code snippet to achieve the desired behavior:
    public class MyAutoCompleteBoxInputHandler : AutoCompleteBoxInputHandler
        public MyAutoCompleteBoxInputHandler(RadAutoCompleteBoxElement element)
            : base(element)
        protected override bool ProcessTabKey(KeyEventArgs e)
            TextPosition position = this.TextBox.Navigator.CaretPosition;
            if (position.TextBlock is TextBlockElement)
                RadAutoCompleteBoxElement element = this.TextBox as RadAutoCompleteBoxElement;
                this.TextBox.ViewElement.Insert(position, element.Delimiter.ToString());
                return false;
            else if (!object.Equals(position, TextPosition.GetLastPosition(this.TextBox.ViewElement)))
                this.TextBox.Navigator.CaretPosition = this.TextBox.Navigator.GetNextPosition(position);
                return false;
            return base.ProcessTabKey(e);

    Then you should replace the default instance by using the following line:
    this.radAutoCompleteBox1.TextBoxElement.InputHandler = new MyAutoCompleteBoxInputHandler(this.radAutoCompleteBox1.TextBoxElement as RadAutoCompleteBoxElement);

    I hope that you find this information useful.

    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top