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

Add new item to suggestion list with what the user typed

1 Answer 57 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
RENAUD
Top achievements
Rank 1
RENAUD asked on 08 Apr 2013, 01:38 PM
Hi!

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

Example:
- 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.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 11 Apr 2013, 12:34 PM
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

Regards,
Svett
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
AutoCompleteBox
Asked by
RENAUD
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or