Add new item to suggestion list with what the user typed

2 posts, 0 answers
    RENAUD avatar
    2 posts
    Member since:
    Oct 2012

    Posted 08 Apr 2013 Link to this post


    I would like to add some items in the suggestion list as the user type information in it.

    - My list contains A, B, C, D
    - The user type E and press enter.
    - E is added to the list, the UI is refreshed so the little "tag" appear properly

    I'm currently half-way of acheving this. The "E" is added to the list, but I have to erase the text in order to be able to see the E in the suggestion list...

    An "official" code or guideline would help me a lot.

  2. Svett
    Svett avatar
    728 posts

    Posted 11 Apr 2013 Link to this post

    Hello Renaud,

    Thank you for writing.

    You should subscribe to the KeyDown event of the RadAutoCompleteBox control to achieve the desired behavior. You can use the following code snippet:
    private void autoComplete_KeyDown(object sender, KeyEventArgs e)
        if (e.KeyCode == Keys.Enter && !autoComplete.TextBoxElement.IsAutoCompleteDropDownOpen)
            TextPosition textPosition = this.autoComplete.TextBoxElement.Navigator.CaretPosition;
            if (textPosition != null && textPosition.TextBlock is TextBlockElement && textPosition.CharPosition == textPosition.TextBlock.Length)
                this.autoComplete.TextBoxElement.ViewElement.Insert(textPosition, this.autoComplete.Delimiter.ToString());

    I hope this helps

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